From 060a37de4a1f08ffb5939c8fc47a805c5d0d0024 Mon Sep 17 00:00:00 2001 From: Bitflash Date: Fri, 7 Aug 2026 16:46:15 -0300 Subject: bignum: shift setint64 in unsigned space to avoid signed overflow UB setint64() extracted big-endian bytes with a signed left shift (n <<= 8). When the top byte is set that overflows int64 -- undefined behaviour, which the script fuzzer flagged under UBSan (bignum.h:158). The result was correct on two's-complement hardware, so this is a latent UB inherited from the original 0.1 code, not a behaviour change. Do the shift on a uint64. --- src/bignum.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/bignum.h b/src/bignum.h index 9da104b..6a295b2 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -155,7 +155,9 @@ public: for (int i = 0; i < 8; i++) { unsigned char c = (n >> 56) & 0xff; - n <<= 8; + n = (int64)((uint64)n << 8); // shift in unsigned space; <<= on a + // signed int64 with the top byte set + // is overflow UB (fuzzer/UBSan finding) if (fLeadingZeroes) { if (c == 0) -- cgit v1.2.3