Repository navigation
own/rc: three fuzzer finds - closure box lifetime, a break's double release, catch/finally locals - #874
Open
ASDAlexander77 wants to merge 5 commits into
Open
own/rc: three fuzzer finds - closure box lifetime, a break's double release, catch/finally locals#874ASDAlexander77 wants to merge 5 commits into
ASDAlexander77 wants to merge 5 commits into
Conversation
`const n = new N(); { let c = () => n.v.get(); } return n.v.x;` was accepted, and read n
after the inner block freed it: the closure's box owns its copies (phase 4), and a read of
n after the move counted as one through its new owner (spec 29) - but the box dies with the
closure value, which the `let`'s release at the block's end gave back. The reads are now
checked against the closure's ends too (followClosure); one that may go anywhere else is no
owner to read through. Now "'n' is used here after its value was moved", as when the
closure is called.
Found by the differential fuzzer (seed 920187).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… on a break
`for (...) { const n = mk(); if (stop) break; if (c) keep(h, n); }` released n twice on
the break: the release on the ways that do not move n (TSLANG 81, valueUnmovedEdges) went
on every edge into the blocks the move reaches - and from the move those run through the
loop's latch to its header and out to its exit, where n does not live, so the break's
edge into the exit got a release on top of the break's own. The blocks are now only those
n's definition dominates.
Found by the differential fuzzer (seed 920048; a crash under glibc's MALLOC_PERTURB_).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Under -mm=rc such a local took no count: `finally { const k = G; G = mk(5); k.items[0] }`
read the object reassigning G freed (a crash; in a catch clause a wrong value from the
reused block). MLIRGen left these locals unowned while a call inside an exception funclet
was fragile; the example it cited (`catch (e: int) { new Res(); throw 2; }`) no longer
crashes. They are owned now, released where the clause ends, on a return or a break out of
it. The clause still synthesizes no cleanup TryOp of its own, so one an exception leaves
the clause with leaks rather than frees. Under own the shape is refused as before ("borrows
'G' but is used here after 'G' is released or overwritten").
00catch_finally_owned_locals_eh covers a throw, return, break, nested try and rethrow out of
clauses holding owned locals (rc, own, gc, none; JIT and AOT, --di -O0 checked by hand).
Found by the differential fuzzer (seed 920443).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A clause synthesizes no cleanup TryOp, so a nested try's unwind leg - an exception out of
its finally on the way back from a `return` - leaves a clause's owned local unreleased; the
ownership verifier reported it on 00try_return_through_finally (`catch { let b = ...; try {
return b; } finally { ... } } finally { ... }`). While such a clause is generated
(clausesWithNestedTry, a counter on the generator: the hoisting decision runs from the
function's context) its locals own nothing, as every clause local did before.
own_err_borrow_catch_local and own_err_borrow_finally_local now report the clause's local where
it is given what another only borrows, as the same local outside a clause is reported.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the three crashes the differential fuzzer found in seed range 920000 (reported in #873). All three were older than #873: the IR was identical with and without it.
1. A value captured by a closure released early (own, seed 920187)
nafter the move counted as a read through its new owner (spec 29,readsThroughOwner), whose lifetime ends were those of the box variable, and it has none. But the box dies with the closure value, which theletreleased at the end of the block.followClosure), and a closure that may go anywhere else is not treated as an owner.own_err_capture_block_closure.2. A value moved on some paths of a loop body, released twice on
break(own, seed 920048)n(TSLANG 81,valueUnmovedEdges) was placed on every edge into the blocks reachable after the move. From the move, those include the loop's latch, header and exit, wherendoes not live. So thebreakedge into the exit got a release on top of thebreak's own release.n's definition dominates are counted.breakreleasesnonce. Test:own_moved_some_paths_break. Before the fix it crashed on Windows and under Linux's poisoning allocator.3. Locals of
catchandfinallyclauses own what they hold (rc and own, seed 920443)catch (e: int) { new Res(); throw 2; }) no longer crashes.returnor abreakout of it.tryof its own keeps its locals unowned (clausesWithNestedTry). The ownership verifier sees thattry's unwind path and would report the leak; it did, on00try_return_through_finally.own_err_borrow_catch_localandown_err_borrow_finally_localare still refused, but now at the declaration ("borrows ... and cannot be stored"), as the same local is outside a clause.00catch_finally_locals_own: rc, gc and none; refused under own.00catch_finally_owned_locals_eh: a throw, return, break, nestedtryand rethrow out of clauses holding owned locals, under every model, JIT and AOT. I also checked it by hand with--diand--opt_level=0.Validation
MALLOC_PERTURB_=165, tcache off)Spec section 87 records the three rules.
🤖 Generated with Claude Code