Skip to content

MemoryError during parse can escalate to SystemError and abort on small input #150001

@StanFromIreland

Description

@StanFromIreland

Crash report

What happened?

string = (
    b'(*h(((h(h(h(' +
    b'[' * 35 +
    b'*h(' +
    b'[' * 38 +
    b'**h(' +
    b'[' * 31 +
    b'(' * 4 +
    b'~' * 20 +
    b'F{' +
    b'[' * 27 +
    b'**h(' +
    b'[' * 31 +
    b'(' * 4 +
    b'~' * 23 +
    b'F{F"{F"{F"{F"{F"{F"{F"{FF""{{F"{""{F"{F{{F"{F"{F"\\}'
)

compile(string, "<input>", "single")

Gives me:

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:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-parsertype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions