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
In file wabt/src/leb128.cc, function ReadU64Leb128:
This snippet is incorrect. It appears to have been copied from ReadU32Leb128:
else if (p + 9 < end && (p[9] & 0x80) == 0) {
// The top bits set represent values > 32 bits.
if (p[9] & 0xf0) {
return 0;
}
*out_value = LEB128_10(uint64_t);
return 10;
}
The right code is:
else if (p + 9 < end && (p[9] & 0x80) == 0) {
// The top bits set represent values > 64 bits.
if (p[9] & 0xfe) {
return 0;
}
*out_value = LEB128_10(uint64_t);
return 10;
}
The number of used bits in byte 10 equals 64 - 9*7 = 1 bit. Only one bit in the final byte is a part of the 64-bit value. Therefore, all the remaining 7 bits of the last byte must be zero. The check for that is if (p[9] & 0xfe) {.
Thank you! This sounds reasonable but I haven't double-checked this myself -- are you up for submitting a PR with a regression test (please see the test/regress directory for some examples)?
Activity
keithw commentedon Apr 12, 2023
Thank you! This sounds reasonable but I haven't double-checked this myself -- are you up for submitting a PR with a regression test (please see the test/regress directory for some examples)?
kssreeram commentedon Apr 21, 2023
I'll give it a shot this weekend.
src/leb128.cc: fix detection of too-big u64 LEB128s