Author xxm
Recipients gvanrossum, xxm
Date 2021-01-12.08:00:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1610438433.18.0.928156683855.issue42889@roundup.psfhosted.org>
In-reply-to
Content
Nice suggestion! I change the argument and I can' find segfault program in transforming ast.Name.  But I do find a segfault program in transforming ast.BinOp!

Seeing the following example, this program will cause a segmentation fault on Python 3.10. No error will be reported during tranforming of node, but Python crashes during compiling the modified AST.

====================================
import ast
class RewriteName(ast.NodeTransformer):
    def visit_BinOp(self, node):
        if node.left.value == 1:
            node.left = node
        return node

code = """
mystr  = 1 + (2+3)
"""

myast = ast.parse(code)

transformer = RewriteName()
newast = transformer.visit(myast)

c = compile(newast,'<test>','exec')
exec(c)
===================================

I really think we should add a checker before compiling modified ast node or cancel the function of compiling AST object. An illegal AST of a program should not throw into "compile" function directly.
History
Date User Action Args
2021-01-12 08:00:33xxmsetrecipients: + xxm, gvanrossum
2021-01-12 08:00:33xxmsetmessageid: <1610438433.18.0.928156683855.issue42889@roundup.psfhosted.org>
2021-01-12 08:00:33xxmlinkissue42889 messages
2021-01-12 08:00:33xxmcreate