[crc64] Fix a subtle bug in CRC64 splice-by-8 implementation #627
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: 9b88ce7
9b88ce7 implements a splice-by-8 version of the CRC64 algorithm which
processes 8 bytes per loop iteration. However, the code had a subtle bug
which resulted in the same CRC calculated for different strings and made
some of Xamarin.Android tests to fail. The following strings yielded the
same checksum value:
The raeson for this was subtle (a stupid oversight on my part, really):
the loop fetched values from the input array by using an index into the
array:
However, with
aptr
being declared asbyte* aptr
the indexingoperation returned a single byte instead of the required 64-bit
word (8 bytes) and, thus, on each iteration of the loop 7 bytes of the
input arrays were ignored in calculation, thus causing the collisions.
The fix is to cast
aptr
toulong*
and then index it, extractingthe required 8 bytes.
This commit also adds a test to check for this issue.