bpo-46707: Avoid potential exponential backtracking in some syntax errors (GH-31241)

This commit is contained in:
Pablo Galindo Salgado 2022-02-10 03:37:17 +00:00 committed by GitHub
parent cb68788dca
commit b71dc71905
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 1561 additions and 1544 deletions

View file

@ -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())