You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reduce the issue to a minimal, self-contained, reproducible test case. Avoid dependencies to mathlib4 or std4.
Description
I suspect that the little-endian and big-endian ByteArray functions have their names backwards. The little-endian function seems to convert a ByteArray to a UInt64 by taking the leftmost byte as most significant, and vice-versa.
Steps to Reproduce
It should be easy to check, but here's a minimal reproduction, showing how the current functions seem to get things wrong when reading an ELF binary. Requires a 64 bit ELF binary - I used /bin/true.
def test: IO Unit := do
let bytes ← IO.FS.readBinFile ↑"/bin/true"
if h : bytes.size > 256 then do
IO.println bytes[0x5] -- e_ident[EI_DATA], 1 means little endian, 2 means bigendian
let ph_off := bytes.extract 0x20 0x28 --program header offset in a 64 bit binary, should be 64.
IO.println ph_off
IO.println ph_off.toUInt64LE!
IO.println ph_off.toUInt64BE!
#eval test
Expected behavior:
I would expect the code above to show toUInt64LE! returning 64 for bytes [0x20,0x28) on a little-endian binary, and toUInt64BE! to give a 64 for that range on a big-endian binary.
Actual behavior:
Seems to be the reverse
Versions
4.7.0-rc1
Ubuntu 22.04.1
Additional Information
Impact
The text was updated successfully, but these errors were encountered:
gleachkr
changed the title
Are ByteArray.toInt64LE! and ByteArray.toInt64LE! reversed?
Are ByteArray.toInt64LE! and ByteArray.toInt64BE! reversed?
Mar 12, 2024
fixes#3657
These functions are mostly not used by lean itself, but it does affect
two occurrences of `ByteArray.toUInt64LE! <$> IO.getRandomBytes 8` which
I left as is instead of switching them to use `toUInt64BE!` to preserve
behavior; but they are random bytes anyway seeded by the OS so it's
unlikely any use of them depending on particular values was sound to
begin with.
Co-authored-by: Scott Morrison <[email protected]>
Prerequisites
Description
I suspect that the little-endian and big-endian ByteArray functions have their names backwards. The little-endian function seems to convert a ByteArray to a UInt64 by taking the leftmost byte as most significant, and vice-versa.
Steps to Reproduce
It should be easy to check, but here's a minimal reproduction, showing how the current functions seem to get things wrong when reading an ELF binary. Requires a 64 bit ELF binary - I used
/bin/true
.Expected behavior:
I would expect the code above to show toUInt64LE! returning 64 for bytes [0x20,0x28) on a little-endian binary, and toUInt64BE! to give a 64 for that range on a big-endian binary.
Actual behavior:
Seems to be the reverse
Versions
4.7.0-rc1
Ubuntu 22.04.1
Additional Information
Impact
The text was updated successfully, but these errors were encountered: