Skip to content

fix(zig): bound the single-quote pattern in _build_brace_safe_stream - #1676

Merged
squid-protocol merged 3 commits into
mainfrom
fix/zig-1426-single-quote-bound
Aug 15, 2026
Merged

squid-protocol merged 3 commits into
mainfrom
fix/zig-1426-single-quote-bound

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Fixes #1426. Follow-up to #1419, whose calling-convention/quoted-identifier
fix left this issue's primary repro file (main.zig, 7529 lines) completely
unchanged at 18 found functions -- a separate, pre-existing mechanism.

_build_brace_safe_stream's single-quote pattern was unbounded for zig
(only rust had the bounded {0,10} form). Zig's char literals ('a',
'\n', '\u{1F600}') are just as short-lived as rust's, but zig also has
multi-line \\-prefixed string literals that are never shielded at all
here (a separate, pre-existing gap) -- so a real contraction/possessive
apostrophe inside one of those strings' prose content (confirmed on
main.zig:128, "Compare Zig's CPU feature detection") reached the
unbounded pattern as an unpaired ', which greedily searched forward for
the NEXT unrelated ' (found ~44 lines later, in "won't") and blanked
everything in between -- including the { of a real function's own opening
brace (pub fn log(...) { at line 142).

That single swallowed { desyncs the brace-depth counter for the rest of
the scan: whichever function's body search was already in flight when the
desync hit never finds its real closing brace and instead swallows every
subsequent line until some later, unrelated } happens to rebalance the
count. Confirmed on this exact corpus: main.zig's wasi_cwd (line 60)
swallowed lines 60-7104 (nearly the whole file) as its own "body", hiding
every function after it -- including ZigClang_main and friends, #1419's
own primary repro, which is exactly why that fix left this file's count
unchanged.

Fix

Bounded the pattern to 10 chars for zig, mirroring rust's existing bound
exactly (same idiom, same function, same fix shape).

Verification

$ venv/bin/pytest tests/core_engine/test_detector.py tests/extraction/languages/test_zig.py tests/extraction/languages/test_zig_strict.py -q
273 passed, 2 xfailed

$ tree_sitter_accuracy_audit.py --lang zig
main.zig alone: 18 -> 68 functions found
Full corpus: found_functions 2700 -> 2750, args_exact_match 2700 -> 2750, extra_functions unchanged at 0

$ tree_sitter_accuracy_audit.py --all --ci
31 language(s) checked, all OK

ReDoS probe: 5000-char adversarial single-quote payload -- 0.25ms

crucible_check.py --mode both blessed via --update --yes (expected
cascading drift -- main.zig's function count nearly quadrupling shifts a lot
of downstream stats, which is real signal, not noise). audit_check.py --ci
clean.

Type of change

  • Bug fix
  • Parsing or engine logic (detector.py)

Differential Scan target

Zig parser corpus (zig compiler source) -- the same file the issue's
measurements came from.

Co-Authored-By: Claude Sonnet 5 [email protected]

squid-protocol and others added 3 commits August 15, 2026 16:06
zig's char literals ('a', '\n', '\u{1F600}') are just as short-lived as
rust's, but _build_brace_safe_stream's single-quote pattern was still
unbounded for zig. Zig also has multi-line `\\`-prefixed string literals
that are never shielded at all here (a separate, pre-existing gap) -- so a
real contraction/possessive apostrophe inside one of those strings' prose
content (confirmed on language-crucible's zig/main.zig:128, "Compare Zig's
CPU feature detection") reached the unbounded pattern as an unpaired `'`,
which greedily searched forward for the NEXT unrelated `'` (found ~44 lines
later, in "won't") and blanked everything in between -- including the `{`
of a real function's own opening brace.

That single swallowed `{` desyncs the brace-depth counter for the rest of
the scan: whichever function's body search was already in flight when the
desync hit never finds its real closing brace and instead swallows every
subsequent line until some later, unrelated `}` happens to rebalance the
count. Confirmed on this exact corpus: main.zig's `wasi_cwd` (line 60)
swallowed lines 60-7104 (nearly the whole 7529-line file) as its own
"body", hiding every function after it -- including the 3 named in the
original #1419 fix's primary repro (`ZigClang_main` and friends), which is
why that fix (extern/export calling-convention + quoted-identifier support)
left this file's found-function count completely unchanged at 18.

Bounded the pattern to 10 chars for zig, mirroring rust's existing bound
exactly (same idiom, same function). main.zig alone: 18 -> 68 functions
found. Full zig corpus: found_functions 2700 -> 2750, args_exact_match
2700 -> 2750, zero new extra_functions.

Fixes #1426

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squid-protocol
squid-protocol merged commit b0a3769 into main Aug 15, 2026
27 checks passed
@squid-protocol
squid-protocol deleted the fix/zig-1426-single-quote-bound branch August 15, 2026 20:12
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

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.

zig func_start: main.zig stuck at 18 found functions, unaffected by #1419's extern/quoted-identifier fix

1 participant