]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.9] bpo-41690: Use a loop to collect args in the parser instead of recursion (GH...
authorPablo Galindo <Pablogsal@gmail.com>
Wed, 2 Sep 2020 20:30:51 +0000 (21:30 +0100)
committerGitHub <noreply@github.com>
Wed, 2 Sep 2020 20:30:51 +0000 (21:30 +0100)
commit8de34cdb952a2e3b8d7a9a213845cad01a8cece3
tree539f50127a5a8c0e42983eec54687e0b3c41b30a
parenta763ee3c583e6a2dfe1b1ac0600a48e8a978ed50
[3.9] bpo-41690: Use a loop to collect args in the parser instead of recursion (GH-22053) (GH-22067)

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 4a97b1517a6b5ff22e2984b677a680b07ff0ce11)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Grammar/python.gram
Misc/NEWS.d/next/Core and Builtins/2020-09-02-12-00-57.bpo-41690.Ny-Sfy.rst [new file with mode: 0644]
Parser/pegen/parse.c
Parser/pegen/pegen.c
Parser/pegen/pegen.h