Message384899
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. |
|
Date |
User |
Action |
Args |
2021-01-12 08:00:33 | xxm | set | recipients:
+ xxm, gvanrossum |
2021-01-12 08:00:33 | xxm | set | messageid: <1610438433.18.0.928156683855.issue42889@roundup.psfhosted.org> |
2021-01-12 08:00:33 | xxm | link | issue42889 messages |
2021-01-12 08:00:33 | xxm | create | |
|