summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-06-10 16:21:04 (GMT)
committerGitHub <noreply@github.com>2022-06-10 16:21:04 (GMT)
commitf9d0240db809fbb4443dc8f96a18e4c49af3fb7f (patch)
treed9f7ebf49a52c76e9e5796d470b51a2dede73244 /Parser
parent98558a83976b0279b1404fcb67bc72e7fcf3fe8a (diff)
downloadcpython-f9d0240db809fbb4443dc8f96a18e4c49af3fb7f.zip
cpython-f9d0240db809fbb4443dc8f96a18e4c49af3fb7f.tar.gz
cpython-f9d0240db809fbb4443dc8f96a18e4c49af3fb7f.tar.bz2
gh-93671: Avoid exponential backtracking in deeply nested sequence patterns in match statements (GH-93680)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl> (cherry picked from commit 53a8b17895e91d08f76a2fb59a555d012cd85ab4) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Parser')
-rw-r--r--Parser/parser.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/Parser/parser.c b/Parser/parser.c
index 08bf6d2..8758e9c 100644
--- a/Parser/parser.c
+++ b/Parser/parser.c
@@ -7945,6 +7945,10 @@ closed_pattern_rule(Parser *p)
return NULL;
}
pattern_ty _res = NULL;
+ if (_PyPegen_is_memoized(p, closed_pattern_type, &_res)) {
+ p->level--;
+ return _res;
+ }
int _mark = p->mark;
{ // literal_pattern
if (p->error_indicator) {
@@ -8100,6 +8104,7 @@ closed_pattern_rule(Parser *p)
}
_res = NULL;
done:
+ _PyPegen_insert_memo(p, _mark, closed_pattern_type, _res);
p->level--;
return _res;
}
@@ -9623,6 +9628,10 @@ star_pattern_rule(Parser *p)
return NULL;
}
pattern_ty _res = NULL;
+ if (_PyPegen_is_memoized(p, star_pattern_type, &_res)) {
+ p->level--;
+ return _res;
+ }
int _mark = p->mark;
if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) {
p->error_indicator = 1;
@@ -9707,6 +9716,7 @@ star_pattern_rule(Parser *p)
}
_res = NULL;
done:
+ _PyPegen_insert_memo(p, _mark, star_pattern_type, _res);
p->level--;
return _res;
}