-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XXHash64/32 incorrect one-shot implementation #61878
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue Detailstl;dr: I upgraded one of my apps to .NET 6 and .NET 6 ships their own xxhash64 implementation, which is great. But the output was not consistent with my previous implementation. (beside my not outputting bigendian, but that's a spec thingie).
This should be >=, you're not hashing all data in the bulk block. Funny thing, the incremental version is correct:
Looking through the test cases, I see cases which should test boundaries, but only like 33 and 63, but not testing the power of two case and I don't see any test case (maybe I missed those, the tests are slightly convoluted for these algorithms) which compare one-shot with incremental. The same problem is in XxHash32. Repro: // See https://aka.ms/new-console-template for more information
using System.Security.Cryptography;
for (int i = 127; i <= 129; i++)
{
Console.WriteLine("Bytes-Length: {0}", i);
var bytes = new byte[i];
RandomNumberGenerator.Fill(bytes);
var h = new System.IO.Hashing.XxHash64();
h.Append(bytes);
Console.WriteLine("System.IO.Hashing.XxHash64 Incremental: {0:X}", BitConverter.ToUInt64(h.GetHashAndReset()));
var netOutput = System.IO.Hashing.XxHash64.Hash(bytes);
Console.WriteLine("System.IO.Hashing.XxHash64: {0:X}", BitConverter.ToUInt64(netOutput));
var h2 = new System.IO.Hashing.XxHash32();
h2.Append(bytes);
Console.WriteLine("System.IO.Hashing.XxHash32 Incremental: {0:X}", BitConverter.ToUInt32(h2.GetHashAndReset()));
var netOutput2 = System.IO.Hashing.XxHash32.Hash(bytes);
Console.WriteLine("System.IO.Hashing.XxHash32: {0:X}", BitConverter.ToUInt32(netOutput2));
} Output is:
(note: I don't like the new multi part entry bug template, it is not possible to prepare the report in an external editor anymore or even back it up to an editor, which I usually do, so I don't accidentially loose the content when I close my browser). @bartonjs might be of interest for you.
|
Feel free to pick "blank" from the list of buttons when you open an issue. (I have the same preference) |
tl;dr: I upgraded one of my apps to .NET 6 and .NET 6 ships their own xxhash64 implementation, which is great. But the output was not consistent with my previous implementation. (beside mine not outputting bigendian, but that's a spec thingie).
runtime/src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash64.cs
Line 218 in 69b5d67
This should be >=, you're not hashing all available data in the bulk/stride block.
Funny thing, the incremental version is correct:
runtime/src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash64.cs
Line 92 in 69b5d67
Looking through the test cases, I see cases which should test boundaries, but only like 33 and 63, but not testing the power of two case and I don't see any test case (maybe I missed those, the tests are slightly convoluted for these algorithms) which compare one-shot with incremental.
The same problem is in XxHash32.
Repro:
Output is:
(note: I don't like the new multi part entry bug template, it is not possible to prepare the report in an external editor anymore or even back it up to an editor, which I usually do, so I don't accidentially lose the content when I close my browser).
@bartonjs might be of interest for you.
I'll throw up a PR to fix this, if I'll understand the test cases.
The text was updated successfully, but these errors were encountered: