From e2215daa5aaf6afb437a978b2a4127e0c872018f Mon Sep 17 00:00:00 2001 From: Prafyl <86287866+Prafyl@users.noreply.github.com> Date: Thu, 8 Oct 2026 09:35:34 +0545 Subject: [PATCH] Fix reading of negative 64-bit integers in TBuffer.ntoi8 ~ returns a signed int32, so negative Long64_t values whose low word is below 0x80000000 were read off by +2^32 (e.g. -2^32 came back as 0). Convert ~high and ~low back to unsigned with >>> 0 before combining. --- modules/io.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/io.mjs b/modules/io.mjs index 3f2e5c77c..7108a50f5 100644 --- a/modules/io.mjs +++ b/modules/io.mjs @@ -2477,7 +2477,9 @@ class TBuffer { this.o += 4; if (high < 0x80000000) return (high < 0x200000) ? (high * 0x100000000 + low) : (BigInt(high) * BigInt(0x100000000) + BigInt(low)); - return (~high < 0x200000) ? (-1 - ((~high) * 0x100000000 + ~low)) : (BigInt(-1) - (BigInt(~high) * BigInt(0x100000000) + BigInt(~low))); + // ~ returns signed int32, convert back to unsigned + const nhigh = ~high >>> 0, nlow = ~low >>> 0; + return (nhigh < 0x200000) ? (-1 - (nhigh * 0x100000000 + nlow)) : (BigInt(-1) - (BigInt(nhigh) * BigInt(0x100000000) + BigInt(nlow))); } /** @summary read float */