Repository navigation
-mm=own: fix #869's walk-cut use-after-free; ctor-built nodes, recursive tree insert and parameter walks compile - #870
Merged
Conversation
…lk that assigns its parameter; a walk cut ahead of itself is refused again Three linked-structure shapes #869 left refused now compile, and a hole #869 opened is closed: - A field given to a call that keeps it, refilled from the call's result (`this.head = new Node(v, this.head)`, `t.left = insert(t.left, v)`): the field is given up before the call (ts.TakeOutOfField) and the refill's release stays. Only for a call that never throws, whose other arguments hold no heap block or are the object `new` made. - `__own_no_throw`: the signature pass marks calls whose callees (and all they call) have no throw. Without it a throwing constructor caught by a caller would empty the list where gc and rc keep it. - A parameter (or a `let` given one) whose every assignment reads out of what it holds (`n = n.next`) borrows the caller's value instead of being kept. - Fixed: `const nx = n.next; n.next = null; n = nx` compiled since #869 and read freed memory at run time. A walking `let` frees nothing above the value read only where it is read after being given that value. Spec 83; the user guide and the readiness page are updated. Tests: 00linked_list_build (every model, and -noopt under own), and own_err_list_unlink_walk, _cut_through_alias, _push_ctor_throws, _push_through_this, own_err_tree_field_given_twice, own_err_param_walk_mixed. ctest 7513/7513 on Windows; own and list tests on Linux under MALLOC_PERTURB_ with tcache off 2233/2233; corpus: no file newly refused (00for_condition_narrowing newly compiles, output as gc's); 500 fuzz seeds (936 programs) no failure; native_ts_graphics' own build unchanged; a 20M iteration churn of the new shapes stays flat in memory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ays kept; the in-step cut pinned Review follow-ups to the previous commit: - __own_no_throw also counts ops of the async dialect as throwing (an await rethrows what the awaited body threw). - walksDownOnly accepts only reads, rc's counts and the debugger's record besides its walk-down stores: a swap or a given-away address keeps the parameter kept. - own_err_list_cut_in_step pins the ordering half of the walk-cut fix: `c.next = (c = c.next, null)` crashes at run time on main. own_err_list_cut_through_alias was refused before #869 too. - The user guide and the readiness page say the call must be one of the same module. ctest 7514/7514 on Windows; Linux own and list tests 2234/2234 under MALLOC_PERTURB_ with tcache off; corpus unchanged but the two crash shapes; the default library's own build 219/225 in all four configurations (6 skipped by design). 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.
Fix first: #869 let a walk read freed memory
Since #869,
-mm=ownaccepted a walk that cuts the list ahead of itself, and the program crashed at run time:The compiler before #869 refused both. #869's rule ("a field of what a walking
letholds, overwritten, frees nothing above the value read") held only once thelethad been given that value. Theletread the place hangs from must now come after the assignment, on every path, and no path from it may reach the release through the read again. No release tag contains #869.Linked structures that now compile
this.head = new Node(v, this.head)ts.TakeOutOfField), the result refills itt.left = insert(t.left, v)(recursion on a field, given back)while (n) { k++; n = n.next; }on a parameter__own_no_throw: nothrow, no async, and only calls to functions of this module that also never throw. Without it, a constructor that throws and is caught by a caller would leave the list empty where gc and rc keep it.newmade.this.wrap(this.head)andf(t.l, t.l)stay errors.TakeOutOfFieldleaves its field as it is.Spec section 83. The user guide and
docs/own-readiness.mdare updated, including the #869 hole in the soundness section.Tests
00linked_list_build, run under own, rc, gc and none, and also with-nooptunder own.own_err_list_*cases:own_err_list_unlink_walkandown_err_list_cut_in_step: the crash shapes. Both crash at run time on main.own_err_list_push_ctor_throws,own_err_list_push_through_this,own_err_list_cut_through_alias.own_err_tree_field_given_twiceandown_err_param_walk_mixed.Validation
MALLOC_PERTURB_=165with tcache off: 2234/2234.00for_condition_narrowingnewly compiles and prints what gc prints. On main, the two crash shapes compile and crash at run time.done.. Private memory stays flat at 1.1 MB under own (10 s), against 2.9 MB under gc (38 s).🤖 Generated with Claude Code