Limit parser nesting depth instead of crashing with RecursionError#510
Merged
Merged
Conversation
Deeply nested arrays/inline tables and long dotted keys recursed without bound, so crafted input could kill the process (python-poetry#459). Values nested beyond 100 levels and keys with more than 100 dotted fragments now raise ParseError. Dotted-key parsing itself is now iterative; the cap there guards the recursive container machinery downstream.
frostming
approved these changes
Jun 13, 2026
Contributor
|
Can you also add a bottom line mentioning which agent and model you are using, if any. This will help us evaluate the PR. Thanks! |
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.
Fixes #459 (picking this up since #468 went stale).
Crafted input could crash the process with a
RecursionErrorvia three unbounded recursion paths: nested arrays, nested inline tables, and dotted keys (every fragment recursed through_parse_key/_parse_bare_key, which the issue didn't mention but has the same effect —'a.'*10000 + 'a = 1'also crashed). Values nested more than 100 levels deep and keys with more than 100 dotted fragments now raiseParseErrorwith position info;MAX_NESTING_DEPTHis a class attribute so subclasses can override it.Dotted-key parsing is now a loop instead of recursion (the chain is linear, and
concatflattening is associative so left-to-right building produces identical keys); the cap is still needed there because each fragment creates a level of nested containers and operations likeContainer.parsing()recurse over that tree. Documents at exactly the limit still parse and round-trip — covered in the tests, which all fail withRecursionErroron master.