Skip to content

Commit b2c5aca

Browse files
committed
Make code in c_generator.py break on error
1 parent dbd8985 commit b2c5aca

3 files changed

Lines changed: 299 additions & 0 deletions

File tree

Lib/test/test_compile.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,31 @@ def unused_code_at_end():
911911
'RETURN_VALUE',
912912
list(dis.get_instructions(unused_code_at_end))[-1].opname)
913913

914+
# This is a regression test for CPython bug
915+
# where SystemError was thrown, instead of a MemoryError or Syntax Error
916+
# when compiling python code, generated by a fuzzer
917+
@support.cpython_only
918+
def test_parser_stack_overflow_no_crash(self):
919+
string = (
920+
b'(*h(((h(h(h(' +
921+
b'[' * 35 +
922+
b'*h(' +
923+
b'[' * 38 +
924+
b'**h(' +
925+
b'[' * 31 +
926+
b'(' * 4 +
927+
b'~' * 20 +
928+
b'F{' +
929+
b'[' * 27 +
930+
b'**h(' +
931+
b'[' * 31 +
932+
b'(' * 4 +
933+
b'~' * 23 +
934+
b'F{F"{F"{F"{F"{F"{F"{F"{FF""{{F"{""{F"{F{{F"{F"{F"\\}'
935+
)
936+
with self.assertRaises((MemoryError, SyntaxError)):
937+
compile(string, '<input>', "single")
938+
914939
@support.cpython_only
915940
def test_docstring(self):
916941
src = textwrap.dedent("""

0 commit comments

Comments
 (0)