Assertion failure: LoadElement instruction returned value with unexpected type, at js/src/jit/MacroAssembler.cpp:1862
The JavaScript engine's JIT compiler produced code that violated an internal type assertion when running a particular script involving Array.prototype.flat on arrays with a custom prototype object. The reporter could not determine the root cause and only observed a debug assertion failure on one architecture.
Originally disclosed on Mozilla
- Fixed in 6 days
- Paid in 14 days
- Disclosed after 6 days
Our JITing produced ( run with --ion-eager --ion-offthread-compile=off) two crash files, both triggering the assert [here](https://searchfox.org/mozilla-central/source/js/src/jit/MacroAssembler.cpp#1862). Unfortunately, the stack trace wasn't very useful, so I'm not sure what the root cause is. (On x86 this doesn't crash.)
'''
function main() {
let v2 = 0;
do {
const v3 = v2 + 1;
v2 = v3;
} while (v2 < 7);
for (let v7 = 0; v7 < 2; v7++) {
}
let v10 = 0;
while (v10 < 8) {
for (let v14 = 0; v14 < 6; v14++) {
}
const v16 = [13.37,13.37,13.37];
const v18 = [1337,1337];
const v19 = {__proto__:v18,e:1337,valueOf:v16};
for (let v23 = 0; v23 < 100; v23++) {
const v25 = [13.37,v19];
const v26 = v25.flat();
}
}
}
main();
gc();
'''
'''
function main() {
let v2 = 0;
do {
const v3 = v2 + 1;
v2 = v3;
} while (v2 < 7);
for (let v7 = 0; v7 < 2; v7++) {
}
let v10 = 0;
while (v10 < 8) {
for (let v14 = 0; v14 < 6; v14++) {
}
const v16 = [13.37,13.37,13.37];
const v18 = [1337,1337];
const v19 = {__proto__:v18,e:1337,valueOf:v16};
for (let v23 = 0; v23 < 100; v23++) {
const v25 = [13.37,v19];
const v26 = v25.flat();
}
}
}
main();
gc();
'''
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 a mismatch between the value type the JIT's LoadElement code produced and the type the compiler assumed, triggered by flat() on arrays with a custom prototype, but the text does not state the cause.
Impact
The script only triggers a debug assertion in the JIT compiler on one architecture; the text does not show memory corruption or any effect on release builds or users.
What the attacker needed
Debug build of the engine; specific JIT flags enabled; non-x86 architecture
How it was found
- Run the engine with the Ion eager and off-thread compile flags disabled.
- Execute the provided script that loops and calls flat() on arrays holding an object with a custom prototype.
- Observe the assertion failure in the JIT MacroAssembler code.
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.
A browser's JavaScript engine sometimes compiles hot code into faster machine code, called JIT compilation. An internal check in that compiler expected a certain kind of value and got a different one, so the debug build stopped with an assertion failure. The reporter only saw a crash in a debug build and did not show that a normal user could be harmed.