authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-03-26 14:10:35+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-03-26 17:06:14+00:00
logbfc0c35689cd5781a3493bdd9c9b8d527847c7a2
tree7ab8e45ba6975c7e5881e2d07ff7c59ba8c933eb
parent951fc09a7e174f8f7cb7384d1fd56dcae9ac73da
signaturelock-open Commit is signed but in an unrecognized format.

Value: fix underflow reading large `u64` values from packed memory


1 files changed, 6 insertions(+), 6 deletions(-)

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