Skip to content

Array literal of a runtime array and a constant one read past the constant; own: s32->s64 union element; rc: delete of a value box - #1102

Merged
ASDAlexander77 merged 1 commit into
mainfrom
leak-fixes-8
Dec 2, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
leak-fixes-8

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

These are fixes from the next round of the ASan corpus sweep. The corpus goes from 124 to 130 of 154 programs clean.

An array literal of a runtime array and a constant one (every model)

  • What broke: [["a" + i, "b"], ["c", "d"]], then any read of an element (data[1], for (const row of data), const [x, y] = data[1]). ASan reported a global-buffer-overflow.
  • Why: ["c", "d"] is a const_array<string, 2>, which widens to the string[] the other element is. Because the widened types matched, the literal made no cast, and the constant's raw data was stored where an array belongs. Reading it read past the global.
  • Fix: an element whose type differs from the array's element type is now cast, unless it is a literal.

-mm=own: a string | s32 element read as string | s64

-mm=rc: delete of a box of a value type

  • What broke: let i = new (TypeOf<1>)(); delete i;. Under rc, delete releases, but value_ref<T> has no release routine, so the block leaked.
  • Fix: the block is now freed outright, after releasing what it holds. Nothing counts references to it: its count stays 0 from creation and nothing retains it.

Tests and results

  • tests/00array_of_arrays_const_element.ts: gc, rc, none and own; JIT and compile.
  • sanitize/leaks_more.ts: gains arraysOfArrays, under rc and own, with and without --di.
  • Full ctest on WSL (ASan build): 10455/10455 passed.
  • ASan corpus: 130/154 clean.

Still not clean (24)

  • Refused under own by earlier rulings:
    • any[k];
    • global initializers;
    • escaping captures;
    • a method stored through an interface;
    • [head, ...tail] of objects;
    • return this from a function expression;
    • [[...t], ...];
    • a nested tuple alias;
    • view() of a global.
  • Probe gaps: Date, console and Reflect are missing because the probes compile with --no-default-lib.
  • Known leftovers:
    • the global counterObj literal under own;
    • using_dispose_throws: a throw from a nested dispose skips releases, as its test documents.
    • t_dp5: mixes i64, s64 and s32 and passes numbers to ...string[], which tsc rejects.

🤖 Generated with Claude Code

…stant; own: s32 to s64 union element cast in place; rc: delete of a value box frees it

- `[["a" + i, "b"], ["c", "d"]]`: `["c", "d"]` is a const_array, which widens to the
  string[] the other element is, so the element types matched and no cast was made:
  the constant's data was stored as the array, and reading it read past the global
  (every model). An element whose type differs from the element type, other than a
  literal, is now cast.
- -mm=own: `[["a", 301349860000], ["c", 0]]` is an array of (string | s64)[] and
  (string | s32)[]; the element of the s32 one was cast through `__cast`, whose result
  borrows, and own refused to keep it (`for (const [k, v] of data)`). A member that
  widens into a number member of the target (s32 -> s64, an integer -> a wider
  float) is cast in place by the tag, as `string | s32` -> `string | number` is.
- -mm=rc: `delete i` of `new (TypeOf<1>)()` (a value_ref) released nothing - the
  type has no release routine - and the block leaked. It is freed (no one counts it).

ASan corpus 124 -> 130 of 154 clean; full ctest (WSL ASan) 10455/10455.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit b5d8965 into main Dec 2, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the leak-fixes-8 branch December 2, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant