summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_syntax.py
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2021-12-20 15:43:26 (GMT)
committerGitHub <noreply@github.com>2021-12-20 15:43:26 (GMT)
commite9898bf153d26059261ffef11f7643ae991e2a4c (patch)
tree07923519cbb9265c39c1d7139ae725b4db7ac586 /Lib/test/test_syntax.py
parent6ca78affc8023bc5023189d64d8050857662042a (diff)
downloadcpython-e9898bf153d26059261ffef11f7643ae991e2a4c.zip
cpython-e9898bf153d26059261ffef11f7643ae991e2a4c.tar.gz
cpython-e9898bf153d26059261ffef11f7643ae991e2a4c.tar.bz2
bpo-46110: Add a recursion check to avoid stack overflow in the PEG parser (GH-30177)
Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r--Lib/test/test_syntax.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 6286529..c95bc15 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -1729,6 +1729,14 @@ while 1:
"""
self._check_error(source, "too many statically nested blocks")
+ @support.cpython_only
+ def test_error_on_parser_stack_overflow(self):
+ source = "-" * 100000 + "4"
+ for mode in ["exec", "eval", "single"]:
+ with self.subTest(mode=mode):
+ with self.assertRaises(MemoryError):
+ compile(source, "<string>", mode)
+
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())