Skip to content

Prevent an infinite loop parsing a capture name#3732

Merged
Earlopain merged 1 commit into
ruby:mainfrom
stevenjohnstone:bug/3729
Dec 13, 2025
Merged

Prevent an infinite loop parsing a capture name#3732
Earlopain merged 1 commit into
ruby:mainfrom
stevenjohnstone:bug/3729

Conversation

@stevenjohnstone

Copy link
Copy Markdown
Contributor

Fixes #3729.

@Earlopain

Earlopain commented Nov 19, 2025

Copy link
Copy Markdown
Collaborator

Thanks, can you add a test for this? In test/prism/fixtures create regex_capture.txt or similar that contains /(?<\u{21!3}>foo)/ =~ "foo" and /(?<\u{21!3}>foo)/. When you run tests with UPDATE_SNAPSHOTS=1 bundle exec rake, a snapshot file gets created that you should commit.

(I guess some other parsers we test against may correctly reject this code. If that is the case, simply excluding this new file for them is fine)

@Earlopain Earlopain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. Since this seems to be correctly implemented everywhere but prism, I just dropped the test. I now feel that wasn't such a bright idea after all.

@Earlopain
Earlopain merged commit cf8316d into ruby:main Dec 13, 2025
64 checks passed
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.

Infinite loop/memory exhaustion parsing a rexexp named capture with a malformed unicode escape

2 participants