fix: Fix uncontrolled recursion DoS in parser.py#468
Open
frostming wants to merge 1 commit into
Open
Conversation
Adds a configurable maximum nesting depth (default 100) to prevent RecursionError when parsing deeply nested arrays or inline tables. When the limit is exceeded, a ParseError is raised instead of allowing unbounded recursion that crashes the process. Fixes python-poetry#459 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Hey sorry I just now seen It failed 2 checks, I will try and look in to it and get a fix sometime soon. |
arp242
added a commit
to toml-lang/toml
that referenced
this pull request
May 24, 2026
Recently there have been a few TOML implementations that have added a nesting limit depth to prevent using up huge amount of CPU/memory with a document like "a.«10,000 more» = 1". For example: hukkin/tomli#286 python-poetry/tomlkit#468 BurntSushi/toml@2e90ced6 There's probably more. In a casual quick look, many implementations already have such a limit and if they don't, they probably should. I added a comment in the toml-test README for it, but I think mentioning it in the spec would also be useful. If only to set a recommended lower limit like we do for 64bit ints. This is helpful both for implementation authors (as a reminder they should add such a limit) and users (as a reminder there may be a limit). For example BurntSushi/toml has never had such a limit until recently, even though I've always known this sort of thing is a problem. I ... just never thought of it. This would have been fixed years ago if there had been a comment in the spec. That's probably the same for tomli.
arp242
added a commit
to toml-lang/toml
that referenced
this pull request
May 24, 2026
Recently there have been a few TOML implementations that have added a nesting limit depth to prevent using up huge amount of CPU/memory with a document like "a.«10,000 more» = 1". For example: hukkin/tomli#286 python-poetry/tomlkit#468 BurntSushi/toml@2e90ced6 There's probably more. In a casual quick look, many implementations already have such a limit and if they don't, they probably should. I added a comment in the toml-test README for it, but I think mentioning it in the spec would also be useful. If only to set a recommended lower limit like we do for 64bit ints. This is helpful both for implementation authors (as a reminder they should add such a limit) and users (as a reminder there may be a limit). For example BurntSushi/toml has never had such a limit until recently, even though I've always known this sort of thing is a problem. I ... just never thought of it. This would have been fixed years ago if there had been a comment in the spec. That's probably the same for tomli.
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.
Adds a configurable maximum nesting depth (default 100) to prevent RecursionError when parsing deeply nested arrays or inline tables. When the limit is exceeded, a ParseError is raised instead of allowing unbounded recursion that crashes the process.
Fixes #459