Enforce nesting limit in scanner#329
Merged
Merged
Conversation
perlpunk
reviewed
May 3, 2026
perlpunk
reviewed
May 4, 2026
perlpunk
reviewed
May 4, 2026
perlpunk
reviewed
May 4, 2026
c2fcca0 to
91c2061
Compare
perlpunk
reviewed
May 5, 2026
perlpunk
reviewed
May 5, 2026
MAX_NESTING_LEVEL was only checked in parser.c, so yaml_parser_scan() callers had no depth protection. Deep flow nesting caused O(n²) CPU via simple_keys scanning. Add the limit check in the scanner's yaml_parser_increase_flow_level() and a test.
Address PR review: also enforce MAX_NESTING_LEVEL in yaml_parser_roll_indent() for block nesting, not just flow nesting. Add block nesting test.
Ensure block indent depth and flow level are checked together against MAX_NESTING_LEVEL, not independently. This prevents exceeding the intended limit with e.g. 1000 block indents + 1000 flow levels. Mirrors the approach already used in parser.c.
Add test-nesting binary and DartConfiguration.tcl (generated by cmake CTest).
The scanner now checks combined block+flow nesting depth, making the parser-level checks redundant. Remove them and unify the flow-level check to use STACK_LIMIT for consistency with roll_indent.
77ec266 to
3658f34
Compare
perlpunk
approved these changes
May 5, 2026
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.
MAX_NESTING_LEVEL was only checked in parser.c, so yaml_parser_scan() callers had no depth protection. Deep flow nesting caused O(n²) CPU via simple_keys scanning. Add the limit check in the scanner's
yaml_parser_increase_flow_level() and a test.