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

s390x: XxHash3Tests.Hash_OneShot_Expected and Hash_Streaming_Expected tests fail #78043

Closed
akoeplinger opened this issue Nov 8, 2022 · 2 comments · Fixed by #78084
Closed
Assignees
Labels
arch-s390x Related to s390x architecture (unsupported) area-System.IO.Hashing
Milestone

Comments

@akoeplinger
Copy link
Member

e.g. https://dev.azure.com/dnceng-public/public/_build/results?buildId=76403&view=ms.vss-test-web.build-test-results-tab&runId=1580894&resultId=130159&paneView=debug

Assert.Equal() Failure
Expected: 3402425285238347205
Actual:   18319083679080722056


Stack trace
   at System.IO.Hashing.Tests.XxHash3Tests.Hash_OneShot_Expected() in /_/src/libraries/System.IO.Hashing/tests/XxHash3Tests.cs:line 39
   at System.Reflection.MethodInvoker.InterpretedInvoke(Object obj, Span`1 args, BindingFlags invokeAttr) in /_/src/mono/System.Private.CoreLib/src/System/Reflection/MethodInvoker.Mono.cs:line 33

/cc @nealef @uweigand

@akoeplinger akoeplinger added area-System.Security arch-s390x Related to s390x architecture (unsupported) labels Nov 8, 2022
@akoeplinger akoeplinger added this to the 8.0.0 milestone Nov 8, 2022
akoeplinger added a commit that referenced this issue Nov 8, 2022
@uweigand
Copy link
Contributor

uweigand commented Nov 8, 2022

It seems the failures start occurring once the string length gets larger than 240 bytes. This is when the DeriveSecretFromSeed routine gets first involved, and on initial glance this doesn't appear to be endian safe:

for (int i = 0; i < SecretLengthBytes; i += sizeof(ulong) * 2)
{
    Unsafe.WriteUnaligned(destinationSecret + i, Unsafe.ReadUnaligned<ulong>(defaultSecret + i) + seed);
    Unsafe.WriteUnaligned(destinationSecret + i + 8, Unsafe.ReadUnaligned<ulong>(defaultSecret + i + 8) - seed);
}

The original C implementation has here:

        for (i=0; i < nbRounds; i++) {
            xxh_u64 lo = XXH_readLE64(kSecretPtr + 16*i)     + seed64;
            xxh_u64 hi = XXH_readLE64(kSecretPtr + 16*i + 8) - seed64;
            XXH_writeLE64((xxh_u8*)customSecret + 16*i,     lo);
            XXH_writeLE64((xxh_u8*)customSecret + 16*i + 8, hi);
       }

Looks like this needs byte-swaps at the loads and stores on a big-endian system.

@uweigand
Copy link
Contributor

uweigand commented Nov 8, 2022

CC @stephentoub

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-s390x Related to s390x architecture (unsupported) area-System.IO.Hashing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants