Value: fix underflow reading large u64 values from packed memory

This commit is contained in:
mlugg 2024-03-26 14:10:35 +00:00
parent 951fc09a7e
commit bfc0c35689
No known key found for this signature in database
GPG Key ID: 58978E823BDE3EF9

View File

@ -787,12 +787,12 @@ pub fn readFromPackedMemory(
if (bits == 0) return mod.intValue(ty, 0);
// Fast path for integers <= u64
if (bits <= 64) {
return mod.intValue(
ty,
std.mem.readVarPackedInt(i64, buffer, bit_offset, bits, endian, int_info.signedness),
);
}
if (bits <= 64) switch (int_info.signedness) {
// Use different backing types for unsigned vs signed to avoid the need to go via
// a larger type like `i128`.
.unsigned => return mod.intValue(ty, std.mem.readVarPackedInt(u64, buffer, bit_offset, bits, endian, .unsigned)),
.signed => return mod.intValue(ty, std.mem.readVarPackedInt(i64, buffer, bit_offset, bits, endian, .signed)),
};
// Slow path, we have to construct a big-int
const abi_size = @as(usize, @intCast(ty.abiSize(mod)));