Assertion failure: byteOffset + byteLength <= arrayBuffer->byteLength(), at js/src/vm/TypedArrayObject.cpp:1418
A JavaScript engine assertion fails when constructing a DataView with a detached ArrayBuffer, because the prototype getter detaches the buffer during construction. An attacker could trigger a crash in debug builds, but the text does not claim memory corruption or code execution.
Originally disclosed on Mozilla
- Fixed in 6 months
- Paid in 7 months
- Disclosed after 6 months
m-c 679118259e91
Marked as s-s because it involves detached array buffers.
Assertion failure:
---
Assertion failure: byteOffset + byteLength <= arrayBuffer->byteLength(), at /home/andre/git/mozilla-central/js/src/vm/TypedArrayObject.cpp:1418
---
Test case:
---
var buffer = new ArrayBuffer(10);
var newTarget = Object.defineProperty(function(){}.bind(), "prototype", {
get() {
detachArrayBuffer(buffer, "same-data");
return DataView.prototype;
}
})
Reflect.construct(DataView, [buffer, 0, 1], newTarget);
---
Back trace:
---
0x0000000000e29749 in js::DataViewObject::create (cx=0x7ffff6960000, byteOffset=0, byteLength=1, arrayBuffer=..., protoArg=0x7ffff7e80080)
at /home/andre/git/mozilla-central/js/src/vm/TypedArrayObject.cpp:1418
1418 MOZ_ASSERT(byteOffset + byteLength <= arrayBuffer->byteLength());
(gdb) bt
#0 0x0000000000e29749 in js::DataViewObject::create (cx=0x7ffff6960000, byteOffset=0, byteLength=1, arrayBuffer=..., protoArg=0x7ffff7e80080)
at /home/andre/git/mozilla-central/js/src/vm/TypedArrayObject.cpp:1418
#1 0x0000000000e29fb5 in js::DataViewObject::constructSameCompartment (cx=0x7ffff6960000, bufobj=..., args=...) at /home/andre/git/mozilla-central/js/src/vm/TypedArrayObject.cpp:1522
#2 0x0000000000e2a68a in js::DataViewObject::class_constructor (cx=0x7ffff6960000, argc=3, vp=0x7fffffffc8c8) at /home/andre/git/mozilla-central/js/src/vm/TypedArrayObject.cpp:1604
#3 0x0000000000d0fdc8 in js::CallJSNative (cx=0x7ffff6960000, native=0xe2a558 <js::DataViewObject::class_constructor(JSContext*, unsigned int, JS::Value*)>, args=...)
at /home/andre/git/mozilla-central/js/src/jscntxtinlines.h:232
#4 0x0000000000d0ff25 in js::CallJSNativeConstructor (cx=0x7ffff6960000, native=0xe2a558 <js::DataViewObject::class_constructor(JSContext*, unsigned int, JS::Value*)>, args=...)
at /home/andre/git/mozilla-central/js/src/jscntxtinlines.h:265
#5 0x0000000000ce8132 in InternalConstruct (cx=0x7ffff6960000, args=...) at /home/andre/git/mozilla-central/js/src/vm/Interpreter.cpp:544
#6 0x0000000000ce84ab in js::Construct (cx=0x7ffff6960000, fval=..., args=..., newTarget=..., objp=...) at /home/andre/git/mozilla-central/js/src/vm/Interpreter.cpp:595
#7 0x0000000000ed95ac in Reflect_construct (cx=0x7ffff6960000, argc=3, vp=0x7ffff3e3f090) at /home/andre/git/mozilla-central/js/src/builtin/Reflect.cpp:113
#8 0x0000000000d0fdc8 in js::CallJSNative (cx=0x7ffff6960000, native=0xed932a <Reflect_construct(JSContext*, unsigned int, JS::Value*)>, args=...)
at /home/andre/git/mozilla-central/js/src/jscntxtinlines.h:232
#9 0x0000000000ce7a1a in js::InternalCallOrConstruct (cx=0x7ffff6960000, args=..., construct=js::NO_CONSTRUCT) at /home/andre/git/mozilla-central/js/src/vm/Interpreter.cpp:453
#10 0x0000000000ce7d5b in InternalCall (cx=0x7ffff6960000, args=...) at /home/andre/git/mozilla-central/js/src/vm/Interpreter.cpp:498
#11 0x0000000000ce7d99 in js::CallFromStack (cx=0x7ffff6960000, args=...) at /home/andre/git/mozilla-central/js/src/vm/Interpreter.cpp:504
#12 0x0000000000cf5309 in Interpret (cx=0x7ffff6960000, state=...) at /home/andre/git/mozilla-central/js/src/vm/Interpreter.cpp:2873
#13 0x0000000000ce7673 in js::RunScript (cx=0x7ffff6960000, state=...) at /home/andre/git/mozilla-central/js/src/vm/Interpreter.cpp:399
#14 0x0000000000ce8c00 in js::ExecuteKernel (cx=0x7ffff6960000, script=..., scopeChainArg=..., newTargetValue=..., evalInFrame=..., result=0x0)
at /home/andre/git/mozilla-central/js/src/vm/Interpreter.cpp:679
#15 0x0000000000ce8ee9 in js::Execute (cx=0x7ffff6960000, script=..., scopeChainArg=..., rval=0x0) at /home/andre/git/mozilla-central/js/src/vm/Interpreter.cpp:712
#16 0x0000000000a42a8c in ExecuteScript (cx=0x7ffff6960000, scope=..., script=..., rval=0x0) at /home/andre/git/mozilla-central/js/src/jsapi.cpp:4313
#17 0x0000000000a42e96 in JS_ExecuteScript (cx=0x7ffff6960000, scriptArg=...) at /home/andre/git/mozilla-central/js/src/jsapi.cpp:4346
#18 0x0000000000436910 in RunFile (cx=0x7ffff6960000, filename=0x7fffffffdfd1 "/tmp/g.js", file=0x7ffff3e3b000, compileOnly=false) at /home/andre/git/mozilla-central/js/src/shell/js.cpp:539
#19 0x0000000000437cd6 in Process (cx=0x7ffff6960000, filename=0x7fffffffdfd1 "/tmp/g.js", forceTTY=false, kind=FileScript) at /home/andre/git/mozilla-central/js/src/shell/js.cpp:860
#20 0x000000000044e941 in ProcessArgs (cx=0x7ffff6960000, op=0x7fffffffd9a0) at /home/andre/git/mozilla-central/js/src/shell/js.cpp:6788
#21 0x000000000044ff27 in Shell (cx=0x7ffff6960000, op=0x7fffffffd9a0, envp=0x7fffffffdbb0) at /home/andre/git/mozilla-central/js/src/shell/js.cpp:7137
#22 0x00000000004514ae in main (argc=2, argv=0x7fffffffdb98, envp=0x7fffffffdbb0) at /home/andre/git/mozilla-central/js/src/shell/js.cpp:7518
---
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 DataView constructor does not re-check whether the ArrayBuffer was detached after calling the prototype getter, so the assertion compares against a stale buffer length.
Impact
The text only shows a debug assertion failure; it does not demonstrate memory corruption or code execution, and the impact on release builds is not stated.
What the attacker needed
Debug build of the JavaScript engine; ability to run JavaScript
How it was found
- Create an ArrayBuffer of length 10.
- Define a custom newTarget whose prototype getter detaches the buffer and returns DataView.prototype.
- Call Reflect.construct(DataView, [buffer, 0, 1], newTarget).
- Observe the assertion failure in DataViewObject::create.
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.
This is a bug in a JavaScript engine (the part of a browser that runs scripts). A DataView is a way to read and write raw bytes in memory. The engine has a safety check that assumes the memory block is still valid, but a script can detach (free) that memory during construction, causing the check to fail and the program to crash.
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.