Skip to content

fix: avoid unbounded recursion in the parser - #22740

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

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
@ChayimFriedman2

Copy link
Copy Markdown
Contributor

The real fix is probably expanding the stack. T-compiler has just accepted a MCP to remove stacker in favor of letting the OS grow the stack. We can do the same - that requires almost zero changes to existing code.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 31, 2026
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.

Avoid unbounded recursion in the parser

3 participants