Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix misaligned reference and logic error in crc32 (apache#1906)
Previously, this code tried to turn a &[u8] into a &[u32] without checking alignment. This means it could and did create misaligned references, which is UB. This can be detected by running the tests with -Zbuild-std --target=x86_64-unknown-linux-gnu (or whatever your host is). This change adopts the approach from the murmurhash implementation. The previous implementation also ignored the tail bytes. The loop at the end treats num_bytes as if it is the full length of the slice, but it isn't, num_bytes number of bytes after the last 4-byte group. This can be observed for example by changing "hello" to just "hell" in the tests. Under the old implementation, the test will still pass. Now, the value that comes out changes, and "hello" and "hell" hash to different values. Can drop this after rebase on commit ded6316 "Fix misaligned reference and logic error in crc32 (apache#1906)", first released in 17.0.0
- Loading branch information