Skip to content

[3.9] bpo-41690: Use a loop to collect args in the parser instead of recursion (GH-22053)#22067

Merged
pablogsal merged 1 commit intopython:3.9from
pablogsal:backport-4a97b15-3.9
Sep 2, 2020
Merged

[3.9] bpo-41690: Use a loop to collect args in the parser instead of recursion (GH-22053)#22067
pablogsal merged 1 commit intopython:3.9from
pablogsal:backport-4a97b15-3.9

Conversation

@pablogsal
Copy link
Member

@pablogsal pablogsal commented Sep 2, 2020

This program can segfault the parser by stack overflow:

import ast

code = "f(" + ",".join(['a' for _ in range(100000)]) + ")"
print("Ready!")
ast.parse(code)

the reason is that the rule for arguments has a simple recursion when collecting args:

args[expr_ty]:
[...]
| a=named_expression b=[',' c=args { c }] {
[...] }.
(cherry picked from commit 4a97b15)

Co-authored-by: Pablo Galindo [email protected]

https://bugs.python.org/issue41690

…recursion (pythonGH-22053)

This program can segfault the parser by stack overflow:

```
import ast

code = "f(" + ",".join(['a' for _ in range(100000)]) + ")"
print("Ready!")
ast.parse(code)
```

the reason is that the rule for arguments has a simple recursion when collecting args:

args[expr_ty]:
    [...]
    | a=named_expression b=[',' c=args { c }] {
        [...] }.
(cherry picked from commit 4a97b15)

Co-authored-by: Pablo Galindo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants