Crash report
What happened?
Summary
When the buffer allocation in decode_unicode_with_escapes() fails while compiling a string literal that contains a backslash escape, the function returns NULL without setting an exception. In a debug build this aborts on assert(PyErr_Occurred()) in _Pypegen_raise_decode_error(). In a release build, compile() raises SyntaxError: invalid syntax for valid source instead of MemoryError.
Reproduction Code
import ast, _testcapi
for n in range(1, 200):
_testcapi.set_nomemory(n, n + 1)
try:
compile("x = '\\n'", "<string>", "exec", ast.PyCF_ONLY_AST)
except MemoryError:
pass
finally:
_testcapi.remove_mem_hooks()
print("done")
Actual Behavior
Debug build (--with-pydebug):
python: Parser/pegen_errors.c:87: _Pypegen_raise_decode_error: Assertion `PyErr_Occurred()' failed.
Aborted (core dumped)
Release build:
Traceback (most recent call last):
File "nomem_repro.py", line 6, in <module>
compile("x = '\\n'", "<string>", "exec", ast.PyCF_ONLY_AST)
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 1
x = '\n'
^^^^
SyntaxError: invalid syntax
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
No response
Linked PRs
Crash report
What happened?
Summary
When the buffer allocation in
decode_unicode_with_escapes()fails while compiling a string literal that contains a backslash escape, the function returnsNULLwithout setting an exception. In a debug build this aborts onassert(PyErr_Occurred())in_Pypegen_raise_decode_error(). In a release build,compile()raisesSyntaxError: invalid syntaxfor valid source instead ofMemoryError.Reproduction Code
Actual Behavior
Debug build (
--with-pydebug):Release build:
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
No response
Linked PRs
decode_unicode_with_escapes()#158311