[naga wgsl-in] Restore accidentally removed recursion depth check.#9424
Merged
teoxoy merged 1 commit intogfx-rs:trunkfrom Apr 14, 2026
Merged
Conversation
Member
Author
|
This bug was not our highest priority, but the process of just filing it was most of the work of fixing it, so I just went ahead and wrote a fix. |
In `naga::front::wgsl::parse`, restore an incorrectly removed call to `Parser::track_recursion`, moving it from `Parser::unary_expression` to `Parser::expression`. To prevent pathological shaders from overflowing the Rust stack, 34cfee6 introduced the `Parser::track_recursion` function to track how deeply the parser has recursed, and throw an uncategorized error if it has far exceeded the depth we expect to encounter while processing any reasonable input. These checks were added to a few strategically chosen functions, such that any recursive execution would need to go through at least one check. When fca3c2e rewrote `Parser::unary_expression` to use a loop instead of recursing, it removed that function's call to `track_recursion`. While it was true that `unary_expression` itself no longer recursed, its call to `track_recursion` was also serving as a choke point for the rest of the expression parser; removing the check reintroduced the potential for unbounded recursion. This commit reintroduces the recursion depth check, but this time places it in `Parser::expression`, a more natural location that is adequate now that `unary_expression` no longer recurses on its own. In local testing, a nesting depth limit of 256 still allowed the Rust stack to overflow, so this patch also lowers the depth limit to 200.
e5b4f4b to
0af9ecf
Compare
teoxoy
approved these changes
Apr 14, 2026
Member
|
The only functions that indirectly recurse:
|
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.
In
naga::front::wgsl::parse, restore an incorrectly removed call toParser::track_recursion, moving it fromParser::unary_expressiontoParser::expression.To prevent pathological shaders from overflowing the Rust stack, 34cfee6 introduced the
Parser::track_recursionfunction to track how deeply the parser has recursed, and throw an uncategorized error if it has far exceeded the depth we expect to encounter while processing any reasonable input. These checks were added to a few strategically chosen functions, such that any recursive execution would need to go through at least one check.When fca3c2e rewrote
Parser::unary_expressionto use a loop instead of recursing, it removed that function's call totrack_recursion. While it was true thatunary_expressionitself no longer recursed, its call totrack_recursionwas also serving as a choke point for the rest of the expression parser; removing the check reintroduced the potential for unbounded recursion.This commit reintroduces the recursion depth check, but this time places it in
Parser::expression, a more natural location that is adequate now thatunary_expressionno longer recurses on its own.In local testing, a nesting depth limit of 256 still allowed the Rust stack to overflow, so this patch also lowers the depth limit to 200.