Skip to content

Limit parser nesting depth instead of crashing with RecursionError#510

Merged
frostming merged 1 commit into
python-poetry:masterfrom
gaoflow:fix-459-recursion-limit
Jun 13, 2026
Merged

Limit parser nesting depth instead of crashing with RecursionError#510
frostming merged 1 commit into
python-poetry:masterfrom
gaoflow:fix-459-recursion-limit

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #459 (picking this up since #468 went stale).

Crafted input could crash the process with a RecursionError via 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 raise ParseError with position info; MAX_NESTING_DEPTH is a class attribute so subclasses can override it.

Dotted-key parsing is now a loop instead of recursion (the chain is linear, and concat flattening 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 like Container.parsing() recurse over that tree. Documents at exactly the limit still parse and round-trip — covered in the tests, which all fail with RecursionError on master.

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
frostming merged commit ea9263f into python-poetry:master Jun 13, 2026
25 checks passed
@frostming

Copy link
Copy Markdown
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!

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.

Security: Uncontrolled Recursion DoS in parser.py (CWE-674)

2 participants