Skip to content

test_stable_hash fails on s390x (big-endian) #15265

Closed
@cuviper

Description

@cuviper
Member

Problem

Since 1.85.0, s390x-unknown-linux-gnu fails on cargo's test_stable_hash. Here's the result on master as of commit c14c1c0:

---- core::source_id::tests::test_stable_hash stdout ----

thread 'core::source_id::tests::test_stable_hash' panicked at src/cargo/core/source_id.rs:823:9:

---- expected: src/cargo/core/source_id.rs:823:46
++++ actual:   In-memory
   1      - 7062945687441624357∅
        1 + 2724068093996237922∅

assert_data_eq!(gen_hash(source_id), str!["7062945687441624357"].raw());

The actual is byte-swapped from the expected value, even though stable-hashing is meant to be platform-agnostic.

Steps

In cargo's own repo: cargo test --lib test_stable_hash

Possible Solution(s)

No response

Notes

I found that rustc-stable-hash adds a .to_le() in its Hasher::finish, which seems suspect:
https://github.com/rust-lang/rustc-stable-hash/blob/24e9848c89917abca155c8f854118e6d00ad4a30/src/sip128.rs#L532

When cargo's test calls .to_string(), that will treat the u64 as native-endian, so it doesn't match the string that a little-endian host would produce.

Similarly, the next line in the test calls short_hash -> to_hex -> to_le_bytes, which will byte-swap it again before hex-printing it.

Version


Activity

added
C-bugCategory: bug
S-triageStatus: This issue is waiting on initial triage.
on Mar 4, 2025
weihanglo

weihanglo commented on Mar 4, 2025

@weihanglo
Member

Does the u64 result from Hasher::finish the same for both big and little endian?

cuviper

cuviper commented on Mar 4, 2025

@cuviper
MemberAuthor

It's the same if you only look at that u64 as little-endian bytes.

cuviper

cuviper commented on Mar 4, 2025

@cuviper
MemberAuthor

I found that rustc-stable-hash adds a .to_le() in its Hasher::finish, which seems suspect:
https://github.com/rust-lang/rustc-stable-hash/blob/24e9848c89917abca155c8f854118e6d00ad4a30/src/sip128.rs#L532

Cc rust-lang/rustc-stable-hash#6 @Urgau -- I'm not sure that to_le() makes sense.

Urgau

Urgau commented on Mar 5, 2025

@Urgau
Member

Indeed my bad, opened rust-lang/rustc-stable-hash#12 to fix it.

Urgau

Urgau commented on Mar 5, 2025

@Urgau
Member

Fix merged and released in rustc-stable-hash 0.1.2.

Only big endian machines were affected, so the hash should only change for them, which doesn't represent much these days. I think that makes it a relatively safe update for Cargo.

added a commit that references this issue on Mar 5, 2025
15f315d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @cuviper@Urgau@weihanglo

      Issue actions

        `test_stable_hash` fails on s390x (big-endian) · Issue #15265 · rust-lang/cargo