Skip to content

Commit e9898bf

Browse files
bpo-46110: Add a recursion check to avoid stack overflow in the PEG parser (GH-30177)
Co-authored-by: Batuhan Taskaya <[email protected]>
1 parent 6ca78af commit e9898bf

File tree

5 files changed

+4608
-3203
lines changed

5 files changed

+4608
-3203
lines changed

Lib/test/test_syntax.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,14 @@ def test_syntax_error_on_deeply_nested_blocks(self):
17291729
"""
17301730
self._check_error(source, "too many statically nested blocks")
17311731

1732+
@support.cpython_only
1733+
def test_error_on_parser_stack_overflow(self):
1734+
source = "-" * 100000 + "4"
1735+
for mode in ["exec", "eval", "single"]:
1736+
with self.subTest(mode=mode):
1737+
with self.assertRaises(MemoryError):
1738+
compile(source, "<string>", mode)
1739+
17321740

17331741
def load_tests(loader, tests, pattern):
17341742
tests.addTest(doctest.DocTestSuite())
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add a maximum recursion check to the PEG parser to avoid stack overflow.
2+
Patch by Pablo Galindo

0 commit comments

Comments
 (0)