Uninitialized Tail Exposure After Resizable ArrayBuffer `transfer()`
Transferring a resizable ArrayBuffer to a smaller length left the hidden grow area uninitialised, and a later resize exposed those stale bytes to JavaScript. An attacker could read leftover memory contents through a typed array or DataView.
- Fixed in 7 days
- Paid in 9 days
- Disclosed after 7 days
Created attachment 9547177 index.html
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Steps to reproduce:
Uninitialized Tail Exposure After Resizable ArrayBuffer transfer()
Summary
When ArrayBuffer.prototype.transfer() is used on a resizable buffer with a
smaller target length, the destination backing store can keep uninitialized
bytes in the hidden grow area. A later resize() growth makes those bytes
visible to JS.
Repro Shape
- Create a resizable buffer:
new ArrayBuffer(16, { maxByteLength: 80 }) - Transfer to a smaller/same length:
transfer(8)ortransfer(16) - Grow back:
resize(80)
Observed: non-zero bytes show up in the expanded tail
Example: 77,77,77,77,77,77,254,255,...
Control case: plain resize shrink/grow (without transfer) keeps tail bytes
at zero.
Call Path
ArrayBuffer.prototype.transfer() enters:
js/src/vm/ArrayBufferObject.cpp:673ArrayBufferObject::transferImpljs/src/vm/ArrayBufferObject.cpp:679ArrayBufferCopyAndDetach(..., PreserveResizability::Yes)
Resizable branch:
js/src/vm/ArrayBufferObject.cpp:520js/src/vm/ArrayBufferObject.cpp:532ResizableArrayBufferObject::copyAndDetach(...)js/src/vm/ArrayBufferObject.cpp:2796ResizableArrayBufferObject::copyAndDetachjs/src/vm/ArrayBufferObject.cpp:2809ResizableArrayBufferObject::copy(...)
Vulnerable copy branch (newByteLength <= sourceByteLength):
js/src/vm/ArrayBufferObject.cpp:2656createBufferAndData<FillContents::Uninitialized>(..., newMaxByteLength, ...)js/src/vm/ArrayBufferObject.cpp:2662only[0..newByteLength)is copied from source
Important detail: for resizable buffers, allocation is sized to maxByteLength
(js/src/vm/ArrayBufferObject.cpp:2563), not just current byteLength.
Root Cause
The bug is an invariant mismatch between copy-time initialization and grow-time assumptions.
Copy-time behavior:
- The transfer-shrink path allocates with
FillContents::Uninitialized. - Only the prefix is copied.
- The remainder
[newByteLength .. maxByteLength)is left uninitialized.
Grow-time behavior:
ResizableArrayBufferObject::resizedoes not zero-fill on growth.- It assumes growth regions are already zeroed by initial allocation or by a previous shrink.
- See
js/src/vm/ArrayBufferObject.cpp:1352tojs/src/vm/ArrayBufferObject.cpp:1355.
Those assumptions are true for normal resize-only flows, but false for this transfer-shrink copy path.
Code Contrast
Uninitialized transfer-shrink copy:
auto [buffer, toFill] = createBufferAndData<FillContents::Uninitialized>(
cx, newByteLength, newMaxByteLength, metadata, nullptr);
std::uninitialized_copy_n(source->dataPointer(), newByteLength, toFill);
js/src/vm/ArrayBufferObject.cpp:2656
Grow path that skips zeroing:
// Clear only on shrink.
if (newByteLength < oldByteLength) {
memset(dataPointer() + newByteLength, 0, oldByteLength - newByteLength);
}
js/src/vm/ArrayBufferObject.cpp:1352
One side creates uninitialized tail bytes, the other side assumes tail bytes are already safe.
Why the Control Case Looks Correct
In resize-only workflows, shrink explicitly clears truncated bytes:
js/src/vm/ArrayBufferObject.cpp:1359
So when the buffer is grown later, the no-zero-on-grow rule is still safe.
transfer(shrink) bypasses that safety guarantee.
Impact
- Class: uninitialized memory exposure
- Surface: JS-readable bytes via
Uint8Array/DataViewafter growth - Conditions:
- resizable ArrayBuffer
transfer(newLen)wherenewLen <= oldLen- later
resize()growth
Fix Direction
Either of these fixes the invariant:
- Use
FillContents::Zeroin the transfer-shrink copy path. - Keep uninitialized allocation, but explicitly
memset(0)for[newByteLength .. maxByteLength)before exposing the new buffer.
The key requirement is that grow-time assumptions must always remain true.
Actual results:
Memory Leak
Expected results:
Not Memory Leak
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
The transfer-shrink copy path allocates the destination with uninitialised contents and copies only the prefix, while the resize growth path assumes the tail is already zeroed.
Impact
Uninitialised memory could be read by JavaScript after growth, potentially disclosing data left in the backing store; the report demonstrates the leak but does not show a full exploit.
What the attacker needed
Resizable ArrayBuffer support; attacker can run JavaScript in the engine
The fix
The transfer-shrink copy path should either zero-fill the allocation or explicitly clear the region between the new length and the maximum length before exposing the buffer.
How it was found
- Create a resizable ArrayBuffer with a maximum length larger than its initial length.
- Transfer it to a length equal to or smaller than the original.
- Resize the resulting buffer up to its maximum length.
- Read the expanded tail through a view and observe non-zero bytes.
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.
An ArrayBuffer is a block of memory that JavaScript code can read and write through views like Uint8Array. When the buffer was shrunk by copying it to a new one, the spare space beyond the copied part was never wiped, so growing it again revealed whatever was previously in memory. That leftover data could contain sensitive information from other parts of the program.
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.