Skip to content

Commit cb604ba

Browse files
Prafyllinev
authored andcommitted
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.
1 parent 7b57145 commit cb604ba

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎modules/io.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,9 @@ class TBuffer {
24772477
this.o += 4;
24782478
if (high < 0x80000000)
24792479
return (high < 0x200000) ? (high * 0x100000000 + low) : (BigInt(high) * BigInt(0x100000000) + BigInt(low));
2480-
return (~high < 0x200000) ? (-1 - ((~high) * 0x100000000 + ~low)) : (BigInt(-1) - (BigInt(~high) * BigInt(0x100000000) + BigInt(~low)));
2480+
// ~ returns signed int32, convert back to unsigned
2481+
const nhigh = ~high >>> 0, nlow = ~low >>> 0;
2482+
return (nhigh < 0x200000) ? (-1 - (nhigh * 0x100000000 + nlow)) : (BigInt(-1) - (BigInt(nhigh) * BigInt(0x100000000) + BigInt(nlow)));
24812483
}
24822484

24832485
/** @summary read float */

0 commit comments

Comments
 (0)