Skip to content

fix: avoid unbounded recursion in the parser#22740

Open
Albab-Hasan wants to merge 1 commit into
rust-lang:masterfrom
Albab-Hasan:parser-recursion-limit
Open

fix: avoid unbounded recursion in the parser#22740
Albab-Hasan wants to merge 1 commit into
rust-lang:masterfrom
Albab-Hasan:parser-recursion-limit

Conversation

@Albab-Hasan

Copy link
Copy Markdown
Contributor

deeply nested input overflows the parser stack and takes the whole process down with it (the 100k nested parens reproducer from #9358 .

track recursion depth on Parser and bail out with an ERROR node past 128 levels. each guard wraps the deepest function of its grammar family and delegates to an _inner fn so no return path can skip leave_recursion. counter instead of unwinding since unwinding past an armed Marker trips its DropBomb. the limit also bounds the syntax tree depth that everything downstream recurses over.

fixes #9824

deeply nested input overflows the parser stack and takes the whole
process down with it (the 100k nested parens reproducer from
rust-lang#9358 .

track recursion depth on `Parser` and bail out with an `ERROR` node past
128 levels. each guard wraps the deepest function of its grammar family
and delegates to an `_inner` fn so no return path can skip
`leave_recursion`. counter instead of unwinding since unwinding past an
armed `Marker` trips its `DropBomb`. the limit also bounds the syntax
tree depth that everything downstream recurses over.

fixes rust-lang#9824
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid unbounded recursion in the parser

2 participants