summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_syntax.py
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2022-02-10 03:37:17 (GMT)
committerGitHub <noreply@github.com>2022-02-10 03:37:17 (GMT)
commitb71dc71905ab674ccaa4a56230d17a28f61c325c (patch)
treeec6148ebc665d0beecc006afd4f6fea6b7139b9a /Lib/test/test_syntax.py
parentcb68788dcadf43b47292bab7816a5ed9efa69730 (diff)
downloadcpython-b71dc71905ab674ccaa4a56230d17a28f61c325c.zip
cpython-b71dc71905ab674ccaa4a56230d17a28f61c325c.tar.gz
cpython-b71dc71905ab674ccaa4a56230d17a28f61c325c.tar.bz2
bpo-46707: Avoid potential exponential backtracking in some syntax errors (GH-31241)
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 a6ff319..8ddfe91 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -1770,6 +1770,14 @@ while 1:
with self.assertRaises(MemoryError):
compile(source, "<string>", mode)
+ @support.cpython_only
+ def test_deep_invalid_rule(self):
+ # Check that a very deep invalid rule in the PEG
+ # parser doesn't have exponential backtracking.
+ source = "d{{{{{{{{{{{{{{{{{{{{{{{{{```{{{{{{{ef f():y"
+ with self.assertRaises(SyntaxError):
+ compile(source, "<string>", "exec")
+
def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())