diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2022-06-10 15:56:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-10 15:56:45 (GMT) |
commit | 53a8b17895e91d08f76a2fb59a555d012cd85ab4 (patch) | |
tree | 4e448db2e89b367fc012d1b5eff0c865f0954b16 /Parser | |
parent | 21a9a85ff4d62e8fc5a51b8eb56154f32c319b77 (diff) | |
download | cpython-53a8b17895e91d08f76a2fb59a555d012cd85ab4.zip cpython-53a8b17895e91d08f76a2fb59a555d012cd85ab4.tar.gz cpython-53a8b17895e91d08f76a2fb59a555d012cd85ab4.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>
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/parser.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Parser/parser.c b/Parser/parser.c index 31ad9a0..50fd03c 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; } |