brandondahler / Data.HashFunction

C# library to create a common interface to non-cryptographic hash functions.
MIT License
255 stars 42 forks source link

xxHash sometimes doesn't match the Hash from the C library from Google #16

Closed illcom94 closed 9 years ago

illcom94 commented 9 years ago

I need to be able to verify an xxHash64 that is being generated by another program. Sometimes the xxHash from this code doesn't match, and when I run the C code downloaded from google, it does. https://code.google.com/p/xxhash/

Has anyone else had this issue?

illcom94 commented 9 years ago

I stepped through the code along with the C++ code from google and I've found the issue. xxHash.cs

  1. In ComputeHashInternal() the dataCount variable should be a long instead of an int. On large files, it overflows into negative.
  2. In PostProcess() you have an if statement "if ((remainder.Length % 8) > 4)" this ensures that your code for processing the last 4 bytes of a file will never be hit. It should be changed to " if ((remainder.Length % 8) == 4)".

After these two changes, everything seems to match.

illcom94 commented 9 years ago

After running a few more files I had to make a modification to my #2 fix. The if statement should be "if ((remainder.Length % 8) >= 4)"

brandondahler commented 9 years ago

I'll take a look at as soon as I can. If you know how to submit a pull request with the changes you talked about above, it could significantly help expedite the process.

brandondahler commented 9 years ago

This issue has been addressed in release 1.8.1.