Skip to content

Anchor several regex/substring identifier matches against false-positive suffixes - #1274

Merged
mkarlesky merged 2 commits into
masterfrom
fix/1266-follow-on-symbol-matching-master
Sep 9, 2026
Merged

mkarlesky merged 2 commits into
masterfrom
fix/1266-follow-on-symbol-matching-master

Conversation

@mkarlesky

Copy link
Copy Markdown
Member

Port of #1273 (green on `next_version`) to `master`, for inclusion in 1.1.8.

Follow-on to #1262 and #1266. Both fixes shared the same root cause — an unanchored match mistaking a substring for a whole token — so after each was fixed, I scanned the rest of the codebase for the same pattern. This PR addresses what that scan found.

Confirmed bugs (empirically reproduced)

`generator_test_results_backtrace.rb` — `do_gdb`'s "prefer whichever unresolved member's own symbol is named in the backtrace" search had no `\b` before the escaped symbol:
```ruby
crash_result[:output].match?( /#{Regexp.escape(tc[:symbol])}\s*()\sat/ )
```
A shorter unresolved symbol that's a suffix of a longer one actually named in the frame (e.g. `foo` vs `my_foo`) could steal the crash attribution. Reproduced with a two-member parameterized group.

`generator_test_runner.rb` — `remap_line_numbers!` matched a test name against source lines completely unescaped and unanchored:
```ruby
if (line =~ /#{next_case[:test]}/)
```
A static helper function whose name merely contains a later test's name as a substring (e.g. `reset_test_ab_state()` before `test_ab`) could false-match first, cascading misalignment to every test case after it in the file. Reproduced the same way.

Defensive hardening

  • `c_extractor_declarations.rb`'s `extract_type` replaced `text.rindex(name)` with a `\b`-anchored greedy match (not shown to misfire on realistic declarations, hardened anyway).
  • `generator_test_results_backtrace.rb`'s `extract_simple_crash_output` now `Regexp.escape`s an interpolated filename.

Tests

Same coverage as #1273: new regression tests for both confirmed bugs (verified failing pre-fix, passing after), plus a defensive test for the `extract_type` hardening. Unit tests only, no system tests. `bundle exec rake specs:units` clean (1994 examples, 0 failures, 1 pre-existing unrelated pending).

🤖 Generated with Claude Code

mkarlesky and others added 2 commits September 8, 2026 19:46
…ive suffixes

Follow-on to #1262/#1266, which share the same root cause: an unanchored
match mistaking a substring for a whole token. A scan for the same pattern
elsewhere in the codebase turned up:

- generator_test_results_backtrace.rb: matching an unresolved crashed test
  case's C symbol against a gdb backtrace frame had no \b before the escaped
  symbol, so a shorter unresolved symbol that's a suffix of a longer one
  actually named in the frame (e.g. "foo" vs "my_foo") could steal the crash
  attribution -- confirmed with a two-member parameterized group.

- generator_test_runner.rb: remap_line_numbers! matched a test name against
  source lines completely unescaped and unanchored. A static helper function
  between two test cases whose name merely contains a later test's name as a
  substring (e.g. reset_test_ab_state() before test_ab) could false-match
  first, assigning the wrong line number and cascading misalignment to every
  subsequent test case in the file -- confirmed the same way.

- c_extractor_declarations.rb: extract_type's rindex(name) is a suffix-
  substring risk in principle (not shown to misfire on realistic
  declarations, since everything that could trail a real declared name is
  already stripped before this runs) -- now \b-anchored defensively via a
  single greedy match instead of a raw rindex.

- generator_test_results_backtrace.rb (extract_simple_crash_output): a
  filename interpolated into a regex without Regexp.escape -- hardened even
  though no concrete failing input was found.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
[skip ci]

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@mkarlesky
mkarlesky merged commit b4ff681 into master Sep 9, 2026
@mkarlesky
mkarlesky deleted the fix/1266-follow-on-symbol-matching-master branch September 9, 2026 02:10
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.

1 participant