Skip to content

Enforce nesting limit in scanner#329

Merged
ingydotnet merged 5 commits into
masterfrom
scanner-nesting-level-fix
May 5, 2026
Merged

Enforce nesting limit in scanner#329
ingydotnet merged 5 commits into
masterfrom
scanner-nesting-level-fix

Conversation

@ingydotnet
Copy link
Copy Markdown
Member

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.

Comment thread src/scanner.c Outdated
Comment thread src/scanner.c Outdated
Comment thread CMakeLists.txt
Comment thread .gitignore
@ingydotnet ingydotnet force-pushed the scanner-nesting-level-fix branch from c2fcca0 to 91c2061 Compare May 5, 2026 15:58
@ingydotnet ingydotnet requested a review from perlpunk May 5, 2026 16:04
Comment thread src/scanner.c Outdated
Comment thread src/scanner.c
ingydotnet added 5 commits May 5, 2026 14:33
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.
@ingydotnet ingydotnet force-pushed the scanner-nesting-level-fix branch from 77ec266 to 3658f34 Compare May 5, 2026 18:34
@ingydotnet ingydotnet requested a review from perlpunk May 5, 2026 18:34
@ingydotnet ingydotnet merged commit 849d0ae into master May 5, 2026
8 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.

2 participants