Description
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∅
cargo/src/cargo/core/source_id.rs
Line 823 in c14c1c0
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
weihanglo commentedon Mar 4, 2025
Does the
u64
result fromHasher::finish
the same for both big and little endian?cuviper commentedon Mar 4, 2025
It's the same if you only look at that
u64
as little-endian bytes.cuviper commentedon Mar 4, 2025
Cc rust-lang/rustc-stable-hash#6 @Urgau -- I'm not sure that
to_le()
makes sense.<StableSipHasher128 as Hasher>::finish
not being platform agnostic rust-lang/rustc-stable-hash#12Urgau commentedon Mar 5, 2025
Indeed my bad, opened rust-lang/rustc-stable-hash#12 to fix it.
Urgau commentedon Mar 5, 2025
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.
rustc-stable-hash v0.1.2
#15268Upgrade to `rustc-stable-hash v0.1.2` (#15268)