Repository navigation
Close #602: strict tests for perl, fix 6 real regex bugs - #641
Merged
Merged
Conversation
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
Contributor
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.
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_bridgesfrom #637): an alternative inside a shared\b(...)\bwrapper that ends on a non-word character, so the trailing\bcan 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 formeval { risky(); }never matched at all -- only the rare unspacedeval{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|{)andgoto\s+&both end on a non-word character by construction (the negative lookahead guarantees it).eval $code;,eval($code);, andgoto &$sub;-- the most common dangerous dynamic-eval/dynamic-dispatch idioms -- never matched. Added a dedicatedeval\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 safeeval 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*\(andsubscribe\s*\(both end in a literal(. The near-universal call shapeon('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 thes////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, andargs/func_startboth firing on the same livesub 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, anddecorators-- no timing findings. Addedassert_redos_immuneregression 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 oneExpected N, Got 0case (bugzilla/Auth.pm's Regex Execution: 5 -> 0) was traced to the oldregex_executionbug -- 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 passedpytest tests/ -m "not golden_crucible") -- passes (2 pre-existing, unrelated failures confirmed present identically onmain, both isolation-ordering artifacts, not caused by this diff)ruff_audit.py --ci-- no new findingsmypy_audit.py --ci-- no new errorspytest -m golden_cruciblein both full-precision and zero-dependency venvs -- both green after fixture regenerationCloses #602