Skip to content

Close #602: strict tests for perl, fix 6 real regex bugs - #641

Merged
squid-protocol merged 1 commit into
mainfrom
test-perl-strict-parsing
Jul 26, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
test-perl-strict-parsing

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Comprehensive strict-parsing test closure for perl (56 signatures, issue #602), continuing the epic #518 initiative. Found and fixed 6 real, currently-shipping bugs during the systematic per-signature review and ambiguity/ReDoS sweep, in addition to the test suite itself.

All 5 of the boundary bugs share the same shape found repeatedly in earlier language closures (haskell, csharp, objective-c, livecode, perl's own ipc_rpc_bridges from #637): an alternative inside a shared \b(...)\b wrapper that ends on a non-word character, so the trailing \b can only fire when a word character happens to immediately follow -- which is often not how the real-world idiom is written.

Bugs found and fixed

  • safety: eval[ \t]*\{ ended on { (non-word). The idiomatic spaced form eval { risky(); } never matched at all -- only the rare unspaced eval{risky()} did. This silently blinded the safety sensor to Perl's single most common error-trapping idiom. Also widened to allow vertical placement (eval\n{), matching perl's own func_start "vertical shield."
  • safety_bypasses: eval\s+(?!\w|{) and goto\s+& both end on a non-word character by construction (the negative lookahead guarantees it). eval $code;, eval($code);, and goto &$sub; -- the most common dangerous dynamic-eval/dynamic-dispatch idioms -- never matched. Added a dedicated eval\s*\( alternative for the no-space call form (naively widening \s+ to \s* doesn't work here since \s* can backtrack to zero-width and re-admit the safe eval q{1} / eval { ... } forms this guard exists to exclude).
  • globals: $$, $@, $!, $? (PID, eval error, errno, child exit status -- 4 of the most common Perl magic variables) all end on a symbolic character. Silently never matched.
  • listeners: on\s*\( and subscribe\s*\( both end in a literal (. The near-universal call shape on('event', ...) (paren immediately followed by a quote) never matched.
  • regex_execution (distinct bug, not the boundary shape): the delimiter check \s*[/\W] could be satisfied by any non-word character, including plain whitespace -- so an ordinary bareword-named scalar ($s, $m, $y, $tr) followed by any operator ($s = 5;) was misclassified as the s////m///y////tr/// regex operator. Narrowed to actual delimiter punctuation and dropped the whitespace tolerance.

Each fix is verified with before/after empirical checks against realistic snippets, not just the automated scanner's raw hit.

Ambiguity sweep

The automated literal-keyword sweep flagged 4 pairs sharing "sub"/"method"/"class"/"package": args<->dead_code, args<->func_start, class_start<->dead_code, dead_code<->func_start. Verified empirically (not just trusted): all 4 are false positives -- dead_code's leading # comment-prefix requirement already fully disambiguates it, and args/func_start both firing on the same live sub foo (...) { line is correct intentional overlap, not a collision. Documented with a dedicated regression test.

ReDoS

Ran the generic 6-payload-shape sweep at n=10000 (wider than the 3000 default) plus targeted adversarial payloads against class_start's ::-chain, args' unclosed-paren form, state_mutation's chained dereference, and decorators -- no timing findings. Added assert_redos_immune regression tests for the ones with the least-obviously-bounded quantifiers.

Golden master

Regenerated both fixtures after manual diff review: all ~400 signal-count deltas confined to perl/ paths, zero non-perl drift. The one Expected N, Got 0 case (bugzilla/Auth.pm's Regex Execution: 5 -> 0) was traced to the old regex_execution bug -- all 5 were false positives from the bareword "s" inside contractions ("there's", "user's"), confirming noise removed rather than signal lost.

Test plan

  • pytest tests/core_engine/test_language_standards_strict.py -k perl -- 64 passed
  • Full suite (pytest tests/ -m "not golden_crucible") -- passes (2 pre-existing, unrelated failures confirmed present identically on main, both isolation-ordering artifacts, not caused by this diff)
  • ruff_audit.py --ci -- no new findings
  • mypy_audit.py --ci -- no new errors
  • pytest -m golden_crucible in both full-precision and zero-dependency venvs -- both green after fixture regeneration

Closes #602

Wrote the comprehensive strict-parsing test suite for perl (56
signatures) and found/fixed 6 real, currently-shipping bugs along the
way, all following the same "\b-wrapped symbolic boundary" shape found
repeatedly in earlier language closures, plus one distinct ambiguity
bug:

- safety: `eval[ \t]*\{` ended on a non-word `{`, so the shared
  trailing \b only matched when a word char immediately followed the
  brace -- the idiomatic spaced form `eval { ... }` never matched at
  all, silently blinding the safety sensor to Perl's primary
  error-trapping idiom. Also widened to allow vertical placement
  (`eval\n{`), matching perl's own func_start vertical shield.
- safety_bypasses: `eval\s+(?!\w|{)` and `goto\s+&` both end on a
  non-word character by construction, so the shared trailing \b could
  never fire -- `eval $code;`, `eval($code);`, and `goto &$sub;` (the
  most common dangerous dynamic-eval/dispatch idioms) never matched.
  Also added a dedicated `eval\s*\(` alternative for the no-space
  function-call form.
- globals: `$$`, `$@`, `$!`, `$?` all end on a symbolic character, so
  the shared trailing \b could never fire -- 4 of the most common Perl
  magic variables silently never matched.
- listeners: `on\s*\(` and `subscribe\s*\(` both end in a literal `(`,
  so the shared trailing \b failed on the near-universal
  `on('event', ...)` call shape.
- regex_execution: the delimiter check `\s*[/\W]` could be satisfied by
  ordinary whitespace/punctuation with nothing to do with a regex
  delimiter, misclassifying bareword-named scalars ($s, $m, $y, $tr)
  followed by any operator as the s///m//y/// operators. Narrowed to
  real delimiter punctuation and dropped the whitespace tolerance that
  let it re-admit itself via backtracking.
- ipc_rpc_bridges was already fixed in the prior cross-language
  symbolic-\b sweep (#637); this PR completes perl's dedicated test
  closure around it.

Also ran the 4-pair ambiguity-sweep finding for perl
(args/dead_code/func_start/class_start sharing "sub"/"method"/"class"/
"package") through empirical verification: all confirmed false
positives from the sweep's literal-only heuristic, documented with a
dedicated regression test rather than silently trusted.

Golden master fixtures regenerated after manual diff review: all ~400
signal-count deltas confined to perl/ paths, zero non-perl drift, and
the one Expected-N/Got-0 case (Auth.pm's Regex Execution 5->0) traced
to 5 false positives from the word "s" inside contractions
("there's", "user's") -- confirms noise removed, not signal lost.

Closes #602
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit fe97e0d into main Jul 26, 2026
27 checks passed
@squid-protocol
squid-protocol deleted the test-perl-strict-parsing branch July 26, 2026 18:44
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.

Strict parsing tests: perl structural signatures

1 participant