Xinmeng Xia <xi...@smail.nju.edu.cn> added the comment:
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. ---------- type: behavior -> crash _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42889> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com