Skip to content

Fix tcl proc loss after an unterminated double-quote (#3142) - #3149

Merged
squid-protocol merged 2 commits into
mainfrom
fix/tcl-quote-3142
Sep 17, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
fix/tcl-quote-3142

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #3142.

Problem

language-crucible/data/tcl/sqlite/testrunner.tcl declares 40 line-start procs; GitGalaxy's Function Analysis extracted only 22. The 18 missing were a contiguous block (L943–L1426).

Root cause is extraction, not detection. An unterminated double-quote on L823 — malformed TCL in sqlite's own source:

    puts "unknown option: \"$a0\"".  Use --help for more info."

(the 4th quote closes the string, the 5th opens one that never closes) desynced the brace slicer's quote state, so the string mask ran away across the next 18 proc declarations until it happened to resync at L1544.

Fix

Direction 2 from the issue — resync at a line-start proc anchor. In _build_brace_safe_stream, the tcl-specific double-quoted-string pattern now refuses to span a newline that begins a proc:

"(?:[^"\\\n]|\n(?![ \t]*proc\b)|\\.)*"

A runaway/unterminated string can no longer swallow a column-0 proc. Scoped to the elif lang_id == "tcl": branch — no other language's quote handling changes.

Verification

  • Real file: the fixed engine extracts 40 procs from testrunner.tcl (was 22); dirs_nHelper, add_tcl_jobs, must_be_testfixture, add_jobs_from_cmdline all recovered.
  • ReDoS: the three alternation branches are first-character-disjoint → linear; verified against a 50k+ adversarial unterminated string (constant/linear time).
  • New regression test in test_tcl.py; full tcl suite passes; detector.py ruff identical to baseline; no new mypy errors.

@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

squid-protocol and others added 2 commits September 17, 2026 18:31
testrunner.tcl (sqlite) declares 40 line-start procs but GitGalaxy extracted
only 22. An unterminated double-quote in a `puts` on L823 (malformed TCL in
sqlite's own source: `puts "...\"$a0\"".  Use --help..."` has an unbalanced
5th quote) desynced the brace slicer's quote state, so the string mask ran away
across the next 18 proc declarations (L943-L1426) until it happened to resync.

Fix (Direction 2 from the issue -- resync at a line-start `proc` anchor): the
tcl-specific double-quoted-string pattern in `_build_brace_safe_stream` now
refuses to let a string span a newline that begins a `proc` declaration
(`"(?:[^"\\\n]|\n(?![ \t]*proc\b)|\\.)*"`). A runaway/unterminated string can no
longer swallow a column-0 `proc`; the structural anchor survives the desync.
The change is scoped to the `elif lang_id == "tcl":` branch, so no other
language's quote handling is affected.

The alternation's three branches are first-character-disjoint, so the nested
quantifier is linear (no catastrophic backtracking); verified against a 50k+
adversarial unterminated string. On the real testrunner.tcl the engine now
extracts 40 procs (all of dirs_nHelper, add_tcl_jobs, must_be_testfixture,
add_jobs_from_cmdline recovered).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Rebased onto main after #3110/#3115 merged, then regenerated both golden-master
fixtures so they carry those merged changes PLUS the tcl quote-resync fix.
Verified via golden_diff.deep_compare against main: the only drift vs main is
testrunner.tcl's 18 recovered procs and their corpus rollup (Function Analysis
list, archetype mix Many-Arg/Compute/Interface/I-O/Defensive summing to +18,
Structural Magnitude, topo re-solve, State-Mutation / Cascading-Flux drop,
tcl/sqlite directory-group + global rollups). #3110's REGISTRS.asm->hlasm
reclassification is preserved (0 hlasm/assembly diffs vs main). No other file.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@squid-protocol
squid-protocol merged commit a08896a into main Sep 17, 2026
31 checks passed
@squid-protocol
squid-protocol deleted the fix/tcl-quote-3142 branch September 17, 2026 22:39
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.

tcl: a dangling double-quote costs 18 of 40 proc declarations in testrunner.tcl

1 participant