Skip to content

valtree's to_le() actually produces different result on big-endian from little-endian. #103183

Closed

Description

@oli-obk
   For commit https://github.com/rust-lang/rust/pull/96591/commits/e14b34c386ad2809e937e0e6e0379c5cc5474954 , the two `to_le()` actually produces different result on big-endian from little-endian.
// Note: Don't use `StableHashResult` impl of `u64` here directly, since that
// would lead to endianness problems.
let hash: u128 = hasher.finish();
let hash_short = (hash.to_le() as u64).to_le();

Assume hash: u128=0x5e0f03940fda80bb6348c650c7b26618, then on LE, hash_short: u64 = 0x6348c650c7b26618, while BE hash_short: u64 = 0x5e0f03940fda80bb, which fails some unit tests on big endian targets because of hash mismatch.

If it's expected behavior to make hash value the same on BE/LE, code here should remove two to_le calls. We don't need to adjust endianness unless converting between multi-byte integer and byte sequences.

Originally posted by @ecnelises in #96591 (comment)

Activity

  1. Rageking8 commented on Oct 18, 2022

    @Rageking8
    Contributor

    @rustbot label +C-bug

  2. added a commit that references this issue on Oct 22, 2022
  3. ecnelises commented on Nov 23, 2022

    @ecnelises
    Contributor

    Can we close this now? (I forgot to mention Fixed xxxx in commit msg to trigger the bot) Not sure if I have the permission

    @rustbot close

  4. rustbot commented on Nov 23, 2022

    @rustbot
    Collaborator

    Error: The feature close is not enabled in this repository.
    To enable it add its section in the triagebot.toml in the root of the repository.

    Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

  5. added a commit that references this issue on Jan 6, 2023
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: This is a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions