classification
Title: Use a loop to collect args in the parser instead of recursion
Type: Stage: resolved
Components: Versions: Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pablogsal
Priority: normal Keywords: patch

Created on 2020-09-02 10:59 by pablogsal, last changed 2020-09-02 20:31 by pablogsal. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 22053 merged pablogsal, 2020-09-02 10:59
PR 22067 merged pablogsal, 2020-09-02 16:52
Messages (3)
msg376225 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-09-02 10:59
This program can segfault the parser by stackoverflow:

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 }] {
        [...] }

Check https://github.com/we-like-parsers/pegen/issues/245 for more context and informaton
msg376255 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-09-02 16:44
New changeset 4a97b1517a6b5ff22e2984b677a680b07ff0ce11 by Pablo Galindo in branch 'master':
bpo-41690: Use a loop to collect args in the parser instead of recursion (GH-22053)
https://github.com/python/cpython/commit/4a97b1517a6b5ff22e2984b677a680b07ff0ce11
msg376263 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-09-02 20:31
New changeset 8de34cdb952a2e3b8d7a9a213845cad01a8cece3 by Pablo Galindo in branch '3.9':
[3.9] bpo-41690: Use a loop to collect args in the parser instead of recursion (GH-22053) (GH-22067)
https://github.com/python/cpython/commit/8de34cdb952a2e3b8d7a9a213845cad01a8cece3
History
Date User Action Args
2020-09-02 20:31:14pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-09-02 20:31:07pablogsalsetmessages: + msg376263
2020-09-02 16:52:28pablogsalsetpull_requests: + pull_request21157
2020-09-02 16:44:22pablogsalsetmessages: + msg376255
2020-09-02 10:59:35pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request21153
2020-09-02 10:59:21pablogsalcreate