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
MemoryError during parse can escalate to SystemError and abort on small input #150001
Fatal Python error: _Py_CheckFunctionResult: a function returned a result with an exception set
Python runtime state: initialized
MemoryError: Parser stack overflowed - Python source too complex to parse
The above exception was the direct cause of the following exception:
SystemError: <class 'SyntaxWarning'> returned a result with an exception set
Current thread 0x00007efd1b8e8780 [python] (most recent call first):
File "/tmp/repro.py", line 19 in <module>
Aborted (core dumped) ./python /tmp/repro.py
Found by OSS-Fuzz.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Output from running 'python -VV' on the command line:
changed the title [-]`MemoryError` during parse can escalate to `SystemError` and abort on small `input`[/-][+]`MemoryError` during parse can escalate to `SystemError` and abort on small input[/+]on May 18, 2026
I'm starting to look into this. I can confirm this reproduces on main,
cpython main ❯ ./python.exe
Python 3.15.0a8+ (heads/main:299cf3c497, May 18 2026, 11:18:24) [Clang 17.0.0 (clang-1700.6.3.2)] on darwin
...
>>> compile(string, "<input>", "single")
Fatal Python error: _Py_CheckFunctionResult: a function returned a result with an exception set
Python runtime state: initialized
MemoryError: Parser stack overflowed - Python source too complex to parse
The above exception was the direct cause of the following exception:
SystemError: <class 'SyntaxWarning'> returned a result with an exception set
...
I couldn't reproduce this with Python 3.14.4 which gives expected SyntaxError.
It seems that there is a recursion limit of 6000 which this code-string seems to be exceeding. The recursion happens with function calls / expressions (~) and maybe other parens ([). This string is only 900 characters so there is the case that there is some pessimization of stack recursion in one of the operators being parsed.
I ran git bisect with the reproducer above. The first bad commit appears to be ccbe41e as the first bad commit.
(where exit code 1 SyntaxError is treated good, and exit code 134 with SystemError /Abort is bad)
The issue was in the Tools/peg_generator/pegen/c_generator.py
So, basically, that particular part (addressed in the PR) was messing with the generated parser.c, which in result escalated to a SystemError with a crash.
Activity
[-]`MemoryError` during parse can escalate to `SystemError` and abort on small `input`[/-][+]`MemoryError` during parse can escalate to `SystemError` and abort on small input[/+]swap357 commentedon May 18, 2026
I'm starting to look into this. I can confirm this reproduces on
main,I couldn't reproduce this with
Python 3.14.4which gives expectedSyntaxError.meghprkh commentedon May 18, 2026
It seems that there is a recursion limit of 6000 which this code-string seems to be exceeding. The recursion happens with function calls / expressions (
~) and maybe other parens ([). This string is only 900 characters so there is the case that there is some pessimization of stack recursion in one of the operators being parsed.swap357 commentedon May 18, 2026
I ran
git bisectwith the reproducer above. The first bad commit appears to be ccbe41e as the first bad commit.(where exit code 1
SyntaxErroris treated good, and exit code 134 withSystemError/Abort is bad)encukou commentedon May 19, 2026
It seems that we're missing some error handling around here:
The challenge now is to figure out where this is generated from :)
sandugood commentedon May 19, 2026
The issue was in the
Tools/peg_generator/pegen/c_generator.pySo, basically, that particular part (addressed in the PR) was messing with the generated
parser.c, which in result escalated to a SystemError with a crash.Merge remote-tracking branch 'upstream/main' into pythongh-150001
Merge remote-tracking branch 'upstream/main' into pythongh-150001
Merge remote-tracking branch 'upstream/main' into pythongh-150001
Merge remote-tracking branch 'upstream/main' into pythongh-150001