Parser stack overflow: deeply-nested source causes SIGSEGV instead of SyntaxError
@sigmaith ci sta già lavorando.
Dal 17/8/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Summary
Parsing deeply-nested Python source (brackets, parens, etc.) crashes the interpreter with SIGSEGV at ~4000 levels of nesting. CPython caps this at 200 via SyntaxError: too many nested parentheses from the parser's internal depth limit.
The crash is in the parser itself (rustpython-ruff_python_parser 0.15.8): compile(src, '<s>', 'exec') (parser + codegen, does NOT go through _ast::ast_to_object) and ast.parse() crash at the identical depth threshold, showing the shared component is the parser, not post-parse conversion.
This is the parser-layer root cause of the class of bugs tracked in #2796. #4857 also still reproduces on current main (closed as fixed in 2023).
Expected
Matches CPython 3.13.4 behavior:
$ python3 -c "import ast; ast.parse('[' * 5000 + '1' + ']' * 5000)"
Traceback (most recent call last):
...
SyntaxError: too many nested parentheses (<unknown>, line 1)
(CPython's parser rejects at depth 201 via a hard-coded limit, well before the native stack is exhausted.)
Actual
$ rustpython -c "import ast; ast.parse('[' * 5000 + '1' + ']' * 5000)"
[no output, exit 139 — SIGSEGV]
$ rustpython -c "src='['*5000+'1'+']'*5000; compile(src,'<s>','exec')"
[no output, exit 139 — SIGSEGV]
# #4857's original reproducer also still crashes:
$ rustpython -c "import ast; ast.parse('+chr(33)' * 1000000)"
[no output, exit 139]
Threshold
| Depth | compile() |
ast.parse() |
|---|---|---|
| 3000 | ok | ok |
| 4000 | SIGSEGV | SIGSEGV |
| 15000 | SIGSEGV | SIGSEGV |
Identical thresholds confirm the crash is in the parser, not in post-parse conversion.
Relation to prior fixes
- #7630 guarded
_ast::ast_from_object(AST object → Rust IR conversion). - #7632 guarded
json.loads()viavm.with_recursion.
Both fixes live downstream of the parser. The parser's own recursive descent has no depth guard, so any Python source deeply nested in brackets, parens, unary ops, or binary ops reaches the native stack limit first.
Environment
- RustPython main @
5a45d41d(parser:rustpython-ruff_python_parser0.15.8) - Compared against: CPython 3.13.4
- macOS 15.1 / Darwin 24.1.0
- Rust release build
- Lingua principale
- Rust
- Stelle
- 22.4k
- Fork
- 1.5k
- Merge medio
- 15h 18m
- PR unite (30g)
- 172
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di RustPython/RustPython
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
RustPython/RustPython#8470 · 2 commenti ·
-
C-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
RustPython/RustPython#7995 · 5 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
RustPython/RustPython#5577 ·
-
C-bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
RustPython/RustPython#8685 · 7 commenti · 1 reazione ·
-
C-compat
RustPython/RustPython#8496 · 1 commento · 1 assegnatario ·
Tutte le issue di RustPython/RustPython
Issue simili
-
risk:low runtime status:in-progress type:test
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
bevyengine/bevy#25861 ·