Assertion failure: !generatorObj->isClosed(), at js/src/debugger/Debugger.cpp:2042
Categories
(Core :: JavaScript Engine, defect, P2)
Tracking
()
People
(Reporter: decoder, Assigned: iain)
References
(Blocks 2 open bugs)
Details
(8 keywords, Whiteboard: [bugmon:update,bisected,confirmed][adv-main149+][adv-ESR140.9+])
Attachments
(2 files, 2 external files)
The following testcase crashes on mozilla-central revision 20260130-20b1a1e6c530 (fuzzing-debug build, run with --fuzzing-safe --no-threads):
See attachment.
Backtrace:
==1739252==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x56e34f41a182 bp 0x7fffdbfc1c50 sp 0x7fffdbfc1c00 T1739252)
==1739252==The signal is caused by a WRITE memory access.
==1739252==Hint: address points to the zero page.
#0 0x56e34f41a182 in MOZ_CrashSequence /builds/worker/workspace/obj-build/dist/include/mozilla/Assertions.h:237:3
#1 0x56e34f41a182 in js::Completion::fromJSFramePop(JSContext*, js::AbstractFramePtr, unsigned char const*, bool) /js/src/debugger/Debugger.cpp:2042:7
#2 0x56e34f418be1 in js::DebugAPI::slowPathOnLeaveFrame(JSContext*, js::AbstractFramePtr, unsigned char const*, bool) /js/src/debugger/Debugger.cpp:1182:16
#3 0x56e34fbdb6a7 in js::DebugAPI::onLeaveFrame(JSContext*, js::AbstractFramePtr, unsigned char const*, bool) /js/src/debugger/DebugAPI-inl.h:83:10
#4 0x56e34fbdb22d in js::jit::DebugEpilogue(JSContext*, js::jit::BaselineFrame*, unsigned char const*, bool) /js/src/jit/VMFunctions.cpp:1083:8
#5 0x56e35024f544 in OnLeaveBaselineFrame /js/src/jit/JitFrames.cpp:388:30
#6 0x56e35024f544 in HandleExceptionBaseline /js/src/jit/JitFrames.cpp:664:3
#7 0x56e35024f544 in js::jit::HandleException(js::jit::ResumeFromException*) /js/src/jit/JitFrames.cpp:828:7
#8 0x2737a0154d65 ([anon:js-executable-memory]+0x1fd65)
==1739252==Register values:
rax = 0x0000000000000000 rbx = 0x00007fffdbfc1d80 rcx = 0x00000000000007fa rdx = 0x0000771d17a04563
rdi = 0x0000771d17a05700 rsi = 0x0000000000000000 rbp = 0x00007fffdbfc1c50 rsp = 0x00007fffdbfc1c00
r8 = 0x0000000000000000 r9 = 0x0000000000000003 r10 = 0x0000000000000002 r11 = 0x0000000000000293
r12 = 0x000021c52d506ce8 r13 = 0x00007fffdbfc1c00 r14 = 0x000056e3776d6e60 r15 = 0x000056e3777b999e
UndefinedBehaviorSanitizer can not provide additional info.
SUMMARY: UndefinedBehaviorSanitizer: SEGV /builds/worker/workspace/obj-build/dist/include/mozilla/Assertions.h:237:3 in MOZ_CrashSequence
==1739252==ABORTING
This bug is part of a series of bugs reported by Anthropic, thank you for your contributions to Firefox!
| Reporter | ||
Comment 1•10 months ago
|
||
| Reporter | ||
Comment 2•10 months ago
|
||
Comment 3•10 months ago
|
||
Verified bug as reproducible on mozilla-central 20260130092147-20b1a1e6c530.
Unable to bisect testcase (Testcase reproduces on start build!):
Start: d0c1a4b1cb725aaff109054e060729eb71099baf (20251102212929)
End: 20b1a1e6c530f3506d5378bf5f4da504b6f03661 (20260130092147)
BuildFlags: BuildFlags(asan=False, tsan=False, debug=True, fuzzing=True, coverage=False, valgrind=False, no_opt=False, fuzzilli=False, nyx=False, searchfox=False, afl=False)
Updated•10 months ago
|
Updated•10 months ago
|
Comment 4•10 months ago
|
||
Setting sec-moderate due to the Debugger hooks requiring the debugger to be enabled.
| Assignee | ||
Comment 5•9 months ago
|
||
There's a lot of fluff in the testcase, but I think this cutdown version captures the actual problem:
let g = newGlobal({ newCompartment: true });
g.eval(`
function* gen() {
yield 1;
}
`)
let dbg = new Debugger(g);
let seen_offsets = new Set();
dbg.onEnterFrame = (frame) => {
frame.onStep = () => {
let offset = frame.offset;
if (!seen_offsets.has(offset)) {
seen_offsets.add(offset);
return { return: 0xdead };
}
}
}
var count;
do {
count = seen_offsets.size;
try {
for (var x of g.gen()) {}
} catch {}
} while (seen_offsets.size > count)
The debugger walks through the different possible offsets in a simple generator, doing a force-return at each one. The bug occurs when we get to the JSOp::Yield. In DebugAPI::onSingleStep, we call ApplyFrameResumeMode, which calls AdjustGeneratorResumptionValue. This closes the generator and wraps the return value (giving {value: 0xdead, done: true}). Then we start propagating a forced return. This eventually causes us to call DebugAPI::onLeaveFrame (the exact route depends on which tier we're executing in, but it doesn't matter), which calls slowPathOnLeaveFrame -> fromJSFramePop.
At that point we see this intriguing comment
// If we're leaving successfully at a yield opcode, we're probably
// suspending; the `isClosed()` check detects a debugger forced return from
// an `onStep` handler, which looks almost the same.
That's precisely the case that we're looking at here. But the only isClosed() check is in the failing assertion. It turns out that this comment was borrowed from an earlier version, which didn't have such an assertion.
I think the fix here is simply to check for a closed generator and fall back to a Return completion in that case.
| Assignee | ||
Comment 6•9 months ago
|
||
Updated•9 months ago
|
Comment 8•9 months ago
|
||
Comment 9•9 months ago
|
||
Verified bug as fixed on rev mozilla-central 20260215214423-7edce67f9460.
Removing bugmon keyword as no further action possible. Please review the bug and re-add the keyword for further analysis.
Comment 10•8 months ago
|
||
Please nominate this for ESR140 uplift when you get a chance.
Comment 11•8 months ago
|
||
firefox-esr140 Uplift Approval Request
- User impact if declined: Using the debugger to force a return at certain points in a generator function may leave the generator in an unexpected state.
- Code covered by automated testing: yes
- Fix verified in Nightly: yes
- Needs manual QE test: no
- Steps to reproduce for manual QE testing:
- Risk associated with taking this patch: low
- Explanation of risk level: The patch can only change behaviour in a case that would previously trigger a debug assertion. The new behaviour is simple and trivial to verify.
- String changes made/needed: None
- Is Android affected?: yes
| Assignee | ||
Comment 12•8 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D283332
Updated•8 months ago
|
Updated•8 months ago
|
Comment 13•8 months ago
|
||
| uplift | ||
Updated•8 months ago
|
Updated•8 months ago
|
| Assignee | ||
Updated•8 months ago
|
Updated•8 months ago
|
Updated•8 months ago
|
Updated•8 months ago
|
Updated•2 months ago
|
Description
•