mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
gh-93671: Avoid exponential backtracking in deeply nested sequence patterns in match statements (GH-93680)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
21a9a85ff4
commit
53a8b17895
4 changed files with 36 additions and 3 deletions
10
Parser/parser.c
generated
10
Parser/parser.c
generated
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue