
Firefox IonMonkey OOB read: a shift constant-folding guard tests the unmasked operand, folding a negative unsigned shift to the wrong sign. ~16 GB out-of-bounds read from plain JS. Fixed in 158.
A constant-folding guard that tested the wrong form of its operand lets plain JavaScript read memory far outside a typed array. Fixed in Firefox 158.
IonMonkey's shift constant-folder knows one case is unsafe to fold: a negative
number shifted by an effective zero, whose unsigned result does not fit in an
int32. The check that refuses the fold tests the shift amount literally. The
fold itself masks the shift amount first. When a shift of 32 slides between
those two questions, Ion folds -4096 >>> 32 into the int32 -4096 instead
of the correct 4294963200, while range analysis keeps believing the result
is non-negative. Every bounds check downstream is built on that belief.
JavaScript masks shift counts, so x >>> 32 is really x >>> 0. For negative
x the answer is the two's-complement value, a number too big for a signed
int32. Ion declines to fold that case because the folded constant would need
a bailout to stay correct:
Firefox 155, js/src/jit/MIR.cpp:
if (lhs < 0 && rhs == 0 && !ins->toUrsh()->bailoutsDisabled()) {
return nullptr;
}
ret = UnsignedInt(lhs) >> (UnsignedInt(rhs) & shiftMask); // shiftMask = 31
Firefox 158:
if (lhs < 0 && (rhs & shiftMask) == 0 &&
!ins->toUrsh()->bailoutsDisabled()) {
return nullptr;
}
The guard asks whether the shift is literally zero. The fold applies the shift
after masking. A shift of 32, 64, or 96 passes the guard, then folds as zero.
For a positive left side that changes nothing. For a negative left side Ion
hands the pipeline an int32 with the wrong sign, and every downstream analysis
still models the Ursh result as the unsigned range [0, 2^32).
That disagreement is the entire bug.
function f(x, go, target) {
var y = x[0] > 255 ? 2048 : -4096;
var res = 0;
if (go) {
y = y >>> 32;
for (var j = 0; j < 2; j++) {
for (var k = y >> 19; k < 4096; k++) {
res = (res + target[k]) | 0;
}
y++;
}
}
return res;
}
The mis-fold produces y = -4096. Range analysis believes y is in
[0, 2^32), so y >> 19 is believed to be [0, 8191], and the loop bound
k < 4096 intersects that with the length of target, a
Uint32Array(4096). Every access is provably in bounds, so the bounds check
is eliminated.
At runtime k = -4096 >> 19 = -1. The load was emitted as an unsigned access,
because its index was proven non-negative. Machine index -1 becomes
0xFFFFFFFF, and the unchecked read lands at dataPtr + 4 * 0xFFFFFFFF.
Sixteen gigabytes past the buffer:
$ js --no-threads poc-157-cve-2026-109721.js
--- SIGSEGV {si_code=SEGV_MAPERR, si_addr=0x744d33b02ffc} ---
The fault address decodes exactly as taBase + 0x3FFFFFFFC, which is
base + 4 * 0xFFFFFFFF.
Swap -4096 for -(1 << 22) and the folded start index becomes -8. The
crash address moves by 28 bytes, exactly (8 - 1) * 4. The primitive reads at
base + 4 * (2^32 + k) for any small negative k. Use a Float64Array and
the window doubles, about 32 GiB out.
In our runs the probe address is unmapped and you get a clean SIGSEGV. With
heap shaping, a landing in mapped memory returns data into res. That is an
infoleak, not a crash. The same range confusion applies to stores
(target[k] = v); we demonstrated the read and left the write as an exercise
for the reader we dislike.