Repository navigation
A template literal argument carries a reference of its own (TSLANG 27) - #777
Merged
Merged
Conversation
A template literal, and an object or literal array printed into a string, built a new string with no reference behind it, unlike `"a" + b`. Passed straight to a call under -mm=rc, a callee that handed its parameter to console.log dropped the count to zero and freed the string before storing it (use after free, then a double free). Under rc and own the same strings were never released (3M template arguments: ~570 MB, now ~50 MB). They now go through markFreshBlockOwned as `+` does: retained and marked, taken over by a receiver or given back at the end of the block. Regression test 00tslang_issue_27.ts under gc, rc, none and own. 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.
What
TSLANG_ISSUES 27: under
-mm=rc, the following crashed on the second call (exit 127):Why
"a" + bgoes throughmarkFreshBlockOwned: the new string is retained and marked__owned_result, so a receiver takes over that reference, or it's given back at the end of the block. A template literal'sts.StringConcatnever went through it, so it reached the callee with a count of 0. In the callee,console.log's rest array retained the argument and released it again. That dropped the count to 0 and freed the string beforethis.message = textstored it. The result was a use after free, then a double free on the next store.Probing found two more places with the same gap: an object or literal array turned into a string (
<string>{ a: i },<string>[1, 2], built incastConstArrayToString/fieldsToString).<string>{ a: i }passed as an argument also crashed under rc.Change
MLIRGenExpressions.cpp(template literal),MLIRGenCast.cpp(castConstArrayToString,fieldsToString): callmarkFreshBlockOwnedon theStringConcatthey build.console.logargument array.TSLANG_ISSUES.md: item 27 is moved into the "fixed" paragraph.Tests
00tslang_issue_27.ts, JIT and compiled, under gc / rc / none / own. Under rc it exits with 127 on pre-alpha116 and passes now.tests.ps1passes for rc and own (186/187 each; the one skip is the gc-only test). The debug pass was not run.Unrelated bug found while probing, not fixed here: a class field
f: (() => number) | nullassigned a function fails to compile with "invalid cast from () => number to () => number | null" under every memory model.🤖 Generated with Claude Code