Incorrect CRC-32 number returned when String or BinaryString contains an integer #14
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/js-crc32#14
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
If you pass in "123456789" (remove double-quotes) into CRC32.bstr() or CRC32.str(), the returned item should be 3421780262 (number) and CBF43926 (hex). Please reference https://www.lammertbies.nl/comm/info/crc-calculation, and https://www.libcrc.org for reference.
Furthermore if any part of the string contains an integer, the CRC32 calculation returned is incorrect.
Please check into this. I have added a Jest based unit test to show the results.
crc32.spec.ts.zip
To be clear:
You can verify this against https://oss.sheetjs.com/js-crc32/ by entering the text in the box:
The returned value is -873187034. To recover the values you expect:
Why is it done this way? For performance reasons. V8 (the engine behind Chrome / NodeJS) and other engines generally treat
Number
s as IEEE754 doubles but optimize for the case of 32-bit signed integers. There's no special case for 32-bit unsigned, so jumping between 32-bit signed and integers >= 2**31 is expensive.In your code, if at all possible try to stick to 32 bit signed integers. If you're reading a checksum from an
ArrayBuffer
, useInt32Array
orDataView#getInt32