From f7603fa87b9c7d153a33a25fed931f647ffec9ca Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Fri, 16 Oct 2026 09:00:37 +0300 Subject: [PATCH] Fix a signed shift overflow in sha256_transform() The message bytes were promoted to int before the shift by 24, which overflows for every byte of 0x80 and above: undefined behaviour that UBSan reports. Widen them to WORD first. The digest does not change. --- src/util/sha256.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/sha256.c b/src/util/sha256.c index eb9c5c07..29b81eed 100644 --- a/src/util/sha256.c +++ b/src/util/sha256.c @@ -46,7 +46,7 @@ void sha256_transform(SHA256_CTX *ctx, const BYTE data[]) WORD a, b, c, d, e, f, g, h, i, j, t1, t2, m[64]; for (i = 0, j = 0; i < 16; ++i, j += 4) - m[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]); + m[i] = ((WORD)data[j] << 24) | ((WORD)data[j + 1] << 16) | ((WORD)data[j + 2] << 8) | ((WORD)data[j + 3]); for ( ; i < 64; ++i) m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16]; -- 2.47.3