You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Handle parser stack overflows more gracefully #22930
Currently, if you have a file that causes a stack overflow in the parser ruff/ty will crash with the usual message thread 'main' (...) has overflowed its stack. It would be nice if there was a better/more clear error when that happens, to differentiate logic-based errors in ruff/ty from "your file is too big/complex" errors.
Version
ruff 0.14.14 (8b2e7b3 2026-01-22) / ty 0.0.14 (16597f5e2 2026-01-26)
I didn't suggest that initially since because in all the things I tried cpython's limits are set lower that where ruff/ty currently stack overflow, so all valid python should also still be covered. It would be cool though.
I think this should now be in a better spot with #25464
This does not protect against downstream tools panicking in a visitor, a function recursively traversing an AST, or even Drop, Eq, Hash etc exceeding the available stack size. If there are cases where you run into this with Ruff or ty, please open an issue with an MRE.
If you run into cases where the parser still overflows, please open an issue with an MRE where we can discuss whether this is reasonable to protect against in Ruff.
Activity
MichaReiser commentedon Mar 2, 2026
I think we should fix the parser instead. It shouldn't panic for any <= 4GB Python file.
This may require rewriting some recursive parsing to use loops or we can dynamically grow the stack size, using something like stacker
MeGaGiGaGon commentedon Mar 2, 2026
I didn't suggest that initially since because in all the things I tried cpython's limits are set lower that where ruff/ty currently stack overflow, so all valid python should also still be covered. It would be cool though.
samuelcolvin commentedon Apr 20, 2026
It's pretty easy to get a stack oveflow which is unfortunate for those of us using ruff to parase untrusted code.
Here's a simple MRE that works with
mainwhen run withcargo run --release -- 5000:add recursion limit for parsing, fix astral-sh#22930
add recursion limit for parsing, fix #22930
add recursion limit for parsing, fix astral-sh#22930
add recursion limit for parsing, fix astral-sh#22930
Add a recursion limit to the parser (#24810)
Add a recursion limit to the parser (astral-sh#24810)
Add a recursion limit to the parser (astral-sh#24810)
MichaReiser commentedon Aug 14, 2026
I think this should now be in a better spot with #25464
This does not protect against downstream tools panicking in a visitor, a function recursively traversing an AST, or even
Drop,Eq,Hashetc exceeding the available stack size. If there are cases where you run into this with Ruff or ty, please open an issue with an MRE.If you run into cases where the parser still overflows, please open an issue with an MRE where we can discuss whether this is reasonable to protect against in Ruff.