Skip to content
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

[release/6.0] Fix XXHash for stripe size #61923

Merged
merged 3 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libraries/System.IO.Hashing/src/System.IO.Hashing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<Nullable>enable</Nullable>
<TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;net461</TargetFrameworks>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<ServicingVersion>1</ServicingVersion>
<!-- TODO: Remove when the package ships with .NET 6. -->
<DisablePackageBaselineValidation>true</DisablePackageBaselineValidation>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this while you are here (and in main). That will enable compat checking with the 6.0.0 package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like something still wants it to check compat with 5.0.0:

src/libraries/System.IO.Hashing/src/System.IO.Hashing.csproj : error NU1102: Unable to find package System.IO.Hashing with version (= 5.0.0)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order for it to look for the 6.0.0 package on the main branch you'd need this change: #61437

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@safern -- I think that means we should add #61437 to the servicing branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jinx 😁 Maybe the way to handle this is to instead remove this property from System.IO.Hashing in #61437 and then bring that whole change to servicing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main was refactored so we would have to do something a little different on servicing, but yeah, I can do something on release/6.0 so that it runs package validation against the 6.0.0 version of the package:

<PackageValidationBaselineVersion Condition="'$(PackageValidationBaselineVersion)' == ''">$([MSBuild]::Subtract($(MajorVersion), 1)).0.0</PackageValidationBaselineVersion>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I included the change directly on this PR

<PackageDescription>Provides non-cryptographic hash algorithms, such as CRC-32.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private static int StaticHash(ReadOnlySpan<byte> source, Span<byte> destination,
int totalLength = source.Length;
State state = new State((uint)seed);

while (source.Length > StripeSize)
while (source.Length >= StripeSize)
{
state.ProcessStripe(source);
source = source.Slice(StripeSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private static int StaticHash(ReadOnlySpan<byte> source, Span<byte> destination,
int totalLength = source.Length;
State state = new State((ulong)seed);

while (source.Length > StripeSize)
while (source.Length >= StripeSize)
{
state.ProcessStripe(source);
source = source.Slice(StripeSize);
Expand Down
7 changes: 7 additions & 0 deletions src/libraries/System.IO.Hashing/tests/XxHash32Tests.007.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public static IEnumerable<object[]> TestCases
private const string DotNetHashesThis3 = DotNetHashesThis + DotNetHashesThis + DotNetHashesThis;
private const string DotNetNCHashing = ".NET now has non-crypto hashing";
private const string DotNetNCHashing3 = DotNetNCHashing + DotNetNCHashing + DotNetNCHashing;
private const string SixteenBytes = ".NET Hashes This";
private const string SixteenBytes3 = SixteenBytes + SixteenBytes + SixteenBytes;

protected static IEnumerable<TestCase> TestCaseDefinitions { get; } =
new[]
Expand Down Expand Up @@ -77,6 +79,11 @@ public static IEnumerable<object[]> TestCases
$"{DotNetNCHashing} (x3)",
Encoding.ASCII.GetBytes(DotNetNCHashing3),
"CABC8ABD"),
// stripe size
new TestCase(
$"{SixteenBytes} (x3)",
Encoding.ASCII.GetBytes(SixteenBytes3),
"AD98EBD3")
};

protected override NonCryptographicHashAlgorithm CreateInstance() => new XxHash32(Seed);
Expand Down
7 changes: 7 additions & 0 deletions src/libraries/System.IO.Hashing/tests/XxHash32Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public static IEnumerable<object[]> TestCases
private const string DotNetHashesThis3 = DotNetHashesThis + DotNetHashesThis + DotNetHashesThis;
private const string DotNetNCHashing = ".NET now has non-crypto hashing";
private const string DotNetNCHashing3 = DotNetNCHashing + DotNetNCHashing + DotNetNCHashing;
private const string SixteenBytes = ".NET Hashes This";
private const string SixteenBytes3 = SixteenBytes + SixteenBytes + SixteenBytes;

protected static IEnumerable<TestCase> TestCaseDefinitions { get; } =
new[]
Expand Down Expand Up @@ -90,6 +92,11 @@ public static IEnumerable<object[]> TestCases
$"{DotNetNCHashing} (x3)",
Encoding.ASCII.GetBytes(DotNetNCHashing3),
"65242024"),
// stripe size
new TestCase(
$"{SixteenBytes} (x3)",
Encoding.ASCII.GetBytes(SixteenBytes3),
"29DA7472")
};

protected override NonCryptographicHashAlgorithm CreateInstance() => new XxHash32();
Expand Down
7 changes: 7 additions & 0 deletions src/libraries/System.IO.Hashing/tests/XxHash32Tests.f00d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public static IEnumerable<object[]> TestCases
private const string DotNetHashesThis3 = DotNetHashesThis + DotNetHashesThis + DotNetHashesThis;
private const string DotNetNCHashing = ".NET now has non-crypto hashing";
private const string DotNetNCHashing3 = DotNetNCHashing + DotNetNCHashing + DotNetNCHashing;
private const string SixteenBytes = ".NET Hashes This";
private const string SixteenBytes3 = SixteenBytes + SixteenBytes + SixteenBytes;

protected static IEnumerable<TestCase> TestCaseDefinitions { get; } =
new[]
Expand Down Expand Up @@ -77,6 +79,11 @@ public static IEnumerable<object[]> TestCases
$"{DotNetNCHashing} (x3)",
Encoding.ASCII.GetBytes(DotNetNCHashing3),
"5A513E6D"),
// stripe size
new TestCase(
$"{SixteenBytes} (x3)",
Encoding.ASCII.GetBytes(SixteenBytes3),
"B38A9A45")
};

protected override NonCryptographicHashAlgorithm CreateInstance() => new XxHash32(Seed);
Expand Down
7 changes: 7 additions & 0 deletions src/libraries/System.IO.Hashing/tests/XxHash64Tests.007.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public static IEnumerable<object[]> TestCases
private const string DotNetNCHashing = ".NET now has non-crypto hashing";
private const string SixtyThreeBytes = "A sixty-three byte test input requires substantial forethought!";
private const string SixtyThreeBytes3 = SixtyThreeBytes + SixtyThreeBytes + SixtyThreeBytes;
private const string ThirtyTwoBytes = "This string has 32 ASCII bytes..";
private const string ThirtyTwoBytes3 = ThirtyTwoBytes + ThirtyTwoBytes + ThirtyTwoBytes;

protected static IEnumerable<TestCase> TestCaseDefinitions { get; } =
new[]
Expand Down Expand Up @@ -87,6 +89,11 @@ public static IEnumerable<object[]> TestCases
$"{SixtyThreeBytes} (x3)",
Encoding.ASCII.GetBytes(SixtyThreeBytes3),
"D6095B93EB10BEDA"),
// stripe size
new TestCase(
$"{ThirtyTwoBytes} (x3)",
Encoding.ASCII.GetBytes(ThirtyTwoBytes3),
"45116421CF932B1F")
};

protected override NonCryptographicHashAlgorithm CreateInstance() => new XxHash64(Seed);
Expand Down
7 changes: 7 additions & 0 deletions src/libraries/System.IO.Hashing/tests/XxHash64Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public static IEnumerable<object[]> TestCases
private const string DotNetNCHashing = ".NET now has non-crypto hashing";
private const string SixtyThreeBytes = "A sixty-three byte test input requires substantial forethought!";
private const string SixtyThreeBytes3 = SixtyThreeBytes + SixtyThreeBytes + SixtyThreeBytes;
private const string ThirtyTwoBytes = "This string has 32 ASCII bytes..";
private const string ThirtyTwoBytes3 = ThirtyTwoBytes + ThirtyTwoBytes + ThirtyTwoBytes;

protected static IEnumerable<TestCase> TestCaseDefinitions { get; } =
new[]
Expand Down Expand Up @@ -103,6 +105,11 @@ public static IEnumerable<object[]> TestCases
$"{SixtyThreeBytes} (x3)",
Encoding.ASCII.GetBytes(SixtyThreeBytes3),
"239C7B3A85BD22B3"),
// stripe size
new TestCase(
$"{ThirtyTwoBytes} (x3)",
Encoding.ASCII.GetBytes(ThirtyTwoBytes3),
"975E3E6FE7E67FBC")
};

protected override NonCryptographicHashAlgorithm CreateInstance() => new XxHash64();
Expand Down
7 changes: 7 additions & 0 deletions src/libraries/System.IO.Hashing/tests/XxHash64Tests.f00d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public static IEnumerable<object[]> TestCases
private const string DotNetNCHashing = ".NET now has non-crypto hashing";
private const string SixtyThreeBytes = "A sixty-three byte test input requires substantial forethought!";
private const string SixtyThreeBytes3 = SixtyThreeBytes + SixtyThreeBytes + SixtyThreeBytes;
private const string ThirtyTwoBytes = "This string has 32 ASCII bytes..";
private const string ThirtyTwoBytes3 = ThirtyTwoBytes + ThirtyTwoBytes + ThirtyTwoBytes;

protected static IEnumerable<TestCase> TestCaseDefinitions { get; } =
new[]
Expand Down Expand Up @@ -87,6 +89,11 @@ public static IEnumerable<object[]> TestCases
$"{SixtyThreeBytes} (x3)",
Encoding.ASCII.GetBytes(SixtyThreeBytes3),
"6F1C62EB48EA2FEC"),
// stripe size
new TestCase(
$"{ThirtyTwoBytes} (x3)",
Encoding.ASCII.GetBytes(ThirtyTwoBytes3),
"B358EB96B8E3E7AD")
};

protected override NonCryptographicHashAlgorithm CreateInstance() => new XxHash64(Seed);
Expand Down