Repository navigation
rc: hold a global argument from its read, and give a const read of a global a count - #647
Merged
Merged
Conversation
…global a count Two shapes the memory-model fuzzer (#646) found double-freeing under rc since #639. - holdGlobalArguments retained the argument right before the call. A later argument of the same call could give the global a new value first (`f(G, (G = mk(), x))`, `f(H.n, (H.n = mk(), x))`): its release freed the block, and the hold then retained and released a freed block. The retain (and the #645 unwind slot) now follow the read. - `const n = G` was folded into the read, holding no count. Once the global got a new value, here or in a call, `n` dangled (fuzzer R1). #639 made that a crash: `run(n.v)`, with `run` assigning G, held and released a field of the freed block. Under rc a const read out of a global, or an interface or bound method made over one, now gets storage like a const read out of a field or an element (#635, #641, #642, #644). Under own the folded read stays a borrow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Oct 23, 2026
A global, or a global's field, given to a call as a view - an interface,
a base class, an object literal holding it - and given a new value by a
later argument of the same call (`f(G, (G = mk(), x))` with an interface
parameter, `f({ v: G.v }, (G = mk(), x))`) was freed before the call ran.
The view is made at the call, after every argument is evaluated, and
holdGlobalArguments did not see through it: `globalOf` stopped at
`ts.NewInterface`, and an object literal holds what it was given with no
count until it is boxed for the interface, at the call too. Under rc the
hold now keeps the value behind the view - the object a cast or an
interface is made over, or each value stored into the literal's slot -
retained where it is read (#647). The fuzzer (#646) found these as A1's
view variant; they failed on #633 as well.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 23, 2026
ASDAlexander77
added a commit
that referenced
this pull request
Oct 23, 2026
* rc: hold an argument whose place the call overwrites An argument is borrowed, and two shapes overwrote the place it was read from while the call still used it: - a later argument of the same call assigns it: `f(n, (n = mk(), n))` for a local, a parameter or a local's field (A1). #647 covered a global; a local was still freed before the call ran. - the callee is given the object as well: `f(n, n.items[0])`, where `f` overwrites `p.items[0]` and then reads its other parameter (R8). Under rc holdGlobalArguments now also holds an argument read out of a slot or a place that something between the read and the call overwrites, and an argument read out of a field or an element of a value given as another argument of the call: retained where it is read, released after the call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * rc: hold an argument read out of a value a later argument reassigns `f({ v: n.v }, (n = mk(), 0))` and `f(n.items[0], (n = mk(), 0))`: the argument is read out of a field or an element of `n`, and the later argument's assignment to `n` gives back the object it was read out of. overwrittenBeforeCall looked only at the argument's own place; it now walks out through the fields and elements it was read through, and holds the argument when any of those values' places is overwritten before the call. Found by the fuzzer (#646) past the first 1000 programs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Oct 23, 2026
…s it (#657) * rc: a local read for an argument is held when a later argument assigns it `g(n, (n = mk(2), 0))`: the arguments are read in order, so the first read `n` and the second gave `n` a new value before the call took the first - and under rc that assignment released the block the callee then read (exit 139, or garbage). The same with a field or an element of a local (`g(h.v, (h.v = mk(), 0))`, also of a folded `const h = new H()`), a conditional argument (its own blocks), a call in a try body, an assigned parameter, and a closure called there that assigns a captured local. Follow-ups 7 and the rc half of 8 (fuzzer A1, local form). holdGlobalArguments now also holds such an argument, as it holds one read out of a global (#647): retained right after the read, released after the call (and in the handler of a try that takes what the call throws). It holds a read of a local when a store into that local, a place in it, or its release - or any call, for a captured local - lies on a path from the read to the call (own_facts::findBetween). The retain goes right after the read also when a conditional argument put the call in a later block of the same region, unless a loop leads back. own still accepts the local forms; that is the own half of follow-up 8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * A Shared handle read for an argument is held when a later argument assigns it `g(s, (s = new Shared(new V(2)), 0))` with `s` a local handle: the assignment gave back the count the old handle held, the last one, and `g` read the freed block. Handles are counted under own too, and the previous commit held such a read under rc only, while own's new check leaves handles to the counts - so own read freed memory. The hold now applies to a handle under own as well, as holdGlobalArguments already does for a handle read out of a global. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77
added a commit
that referenced
this pull request
Oct 23, 2026
…kes it (#660) * rc: a local read for an argument is held when a later argument assigns it `g(n, (n = mk(2), 0))`: the arguments are read in order, so the first read `n` and the second gave `n` a new value before the call took the first - and under rc that assignment released the block the callee then read (exit 139, or garbage). The same with a field or an element of a local (`g(h.v, (h.v = mk(), 0))`, also of a folded `const h = new H()`), a conditional argument (its own blocks), a call in a try body, an assigned parameter, and a closure called there that assigns a captured local. Follow-ups 7 and the rc half of 8 (fuzzer A1, local form). holdGlobalArguments now also holds such an argument, as it holds one read out of a global (#647): retained right after the read, released after the call (and in the handler of a try that takes what the call throws). It holds a read of a local when a store into that local, a place in it, or its release - or any call, for a captured local - lies on a path from the read to the call (own_facts::findBetween). The retain goes right after the read also when a conditional argument put the call in a later block of the same region, unless a loop leads back. own still accepts the local forms; that is the own half of follow-up 8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * A Shared handle read for an argument is held when a later argument assigns it `g(s, (s = new Shared(new V(2)), 0))` with `s` a local handle: the assignment gave back the count the old handle held, the last one, and `g` read the freed block. Handles are counted under own too, and the previous commit held such a read under rc only, while own's new check leaves handles to the counts - so own read freed memory. The hold now applies to a handle under own as well, as holdGlobalArguments already does for a handle read out of a global. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * -mm=own: a local lent to a call cannot be assigned before the call takes it `g(n, (n = mk(2), 0))`: the first argument borrows `n`'s object, and the second gives `n` a new value first, which drops that object before `g` reads it. own accepted it and read freed memory - also through a conditional argument (`g(n, c ? (n = mk(), 0) : 1)`), in a try body, and with a closure called there that assigns a captured `n`. Follow-up 8, own half (fuzzer A1, local form); rc holds such an argument instead (the parent commit). checkArgumentsAssigned rejects an argument read out of an owning local when a store into that local's slot, or its release - or a call, when a closure built over the local assigns it - lies on a path from the read to the call (own_facts::findBetween). A read of a global is already checkGlobalRead's; a store into a field of the local, the place borrows'. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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 rc regression the memory-model fuzzer (#646) reported as A2, bisected to #639. Its four repros turned out to be two bugs.
1. The hold was taken after a later argument freed the block (A2-global, A2-field)
holdGlobalArguments(#639/#643/#645) retained a global-read argument right before the call. A later argument of the same call can give that global a new value first:The
ReleaseSlotof that assignment freed the block the first argument had read. The hold then retained and released a freed block, a double free ("malloc(): unaligned tcache chunk detected", 0xC0000374). Now the retain, and #645's unwind-slot store, come right after the argument's read.2. A const read of a global held no count (A2-callee, A2-callee-try; fuzzer R1)
const n = Gwas folded into the read itself. OnceGgot a new value, here or in a callee,ndangled. Before #639 that was a silent use-after-free. #639's hold onrun(n.v)(withrunassigningG) turned it into a double free. Under rc, a const read out of a global, or an interface or bound method made over one, now gets storage like a const read out of a field or an element (#635, #641, #642, #644). Under own the folded read stays a borrow.This also fixes
R1-own-minimalandR1-const-globalunder rc. R1 under own still crashes and is not touched here. The cost: under rc, a const of any global, even one that is never reassigned (const h = HG), now pays a retain/release pair, as the field and element cases already do.Tests
tests/00global_argument_reassigned.ts: a global and a global's field lent before an argument that assigns them, in a loop, and with a later argument that throws inside a try.tests/00const_global_read.ts: a const of a global reassigned here and in a call, a field of it lent to a call that assigns the global (in a loop, read in a finally), and an interface or bound method over a global.Both run compiled, under JIT, and in the rc/none corpus. Without the hold move,
00global_argument_reassignedfails under rc on Windows too. Both crash under rc on main on Linux.Verification
ctest -C Release: Windows 4970/4970, WSL Linux 4952/4952.mm_fuzz.py --jobs 10 run --count 500 --seed 1on Linux found 10 failures. All 10 fail on main as well, and all 7 rc ones also crash on the JIT: find the GC runtime next to tslang, and say so when it is missing #633 base, so none is A2. The rc failures are A1's view variant: a global or a global's field lent through an interface or object-literal view (f({ v: G.v }, (G = mk(), x)), orHG.nas anIXparameter) and reassigned in a later argument.globalOfdoesn't see through those views, so nothing is held. The 3 own failures are R1 (own) and O4.🤖 Generated with Claude Code