This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: The ast module fails to reject certain malformed nodes
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brandtbucher Nosy List: BTaskaya, brandtbucher, curtisbucher, miss-islington, pablogsal, remi.lapeyre
Priority: normal Keywords: patch

Created on 2020-04-21 19:59 by brandtbucher, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19868 merged curtisbucher, 2020-05-02 21:48
PR 19947 closed miss-islington, 2020-05-05 19:41
Messages (4)
msg366938 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2020-04-21 19:59
There are several places in the ast module where the use of zip is allowing malformed nodes to have unpaired children silently thrown away. A couple of short examples:

>>> from ast import Constant, Dict, literal_eval, unparse
>>> nasty_dict = Dict(keys=[Constant("I don't have a value!")], values=[])
>>> unparse(nasty_dict)
'{}'
>>> literal_eval(nasty_dict)
{}

I'm currently working on a patch to raise errors instead.
msg366941 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2020-04-21 21:03
See https://bugs.python.org/msg360767 for ast.unparse's point of view regarding malformed nodes.
msg368200 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-05-05 19:41
New changeset c21c51235aa8061da6b0593d6f857f42fd92fd8b by Curtis Bucher in branch 'master':
bpo-40355: Improve error messages in ast.literal_eval with malformed Dict nodes (GH-19868)
https://github.com/python/cpython/commit/c21c51235aa8061da6b0593d6f857f42fd92fd8b
msg368202 - (view) Author: miss-islington (miss-islington) Date: 2020-05-05 20:01
New changeset 2a3b876b0286b22a9058510d9e51dc4d60eeb89a by Miss Islington (bot) in branch '3.8':
bpo-40355: Improve error messages in ast.literal_eval with malformed Dict nodes (GH-19868)
https://github.com/python/cpython/commit/2a3b876b0286b22a9058510d9e51dc4d60eeb89a
History
Date User Action Args
2022-04-11 14:59:29adminsetgithub: 84535
2020-05-06 08:21:23BTaskayasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-05-05 20:01:04miss-islingtonsetmessages: + msg368202
2020-05-05 19:41:10miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request19262
2020-05-05 19:41:04pablogsalsetmessages: + msg368200
2020-05-02 21:48:12curtisbuchersetkeywords: + patch
nosy: + curtisbucher

pull_requests: + pull_request19181
stage: patch review
2020-04-21 21:03:28BTaskayasetnosy: + pablogsal, BTaskaya
messages: + msg366941
2020-04-21 20:33:45remi.lapeyresetnosy: + remi.lapeyre
2020-04-21 19:59:22brandtbuchercreate