Skip to content

Commit 02075f8

Browse files
committed
[3.9] bpo-46110: Add a recursion check to avoid stack overflow in the PEG parser (GH-30177)
Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>. (cherry picked from commit e9898bf) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
1 parent 8e4564d commit 02075f8

File tree

4 files changed

+3332
-2323
lines changed

4 files changed

+3332
-2323
lines changed

Lib/test/test_syntax.py

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

1007+
@support.cpython_only
1008+
def test_error_on_parser_stack_overflow(self):
1009+
source = "-" * 100000 + "4"
1010+
for mode in ["exec", "eval", "single"]:
1011+
with self.subTest(mode=mode):
1012+
with self.assertRaises(MemoryError):
1013+
compile(source, "<string>", mode)
1014+
10071015

10081016
def test_main():
10091017
support.run_unittest(SyntaxTestCase)
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)