Author: Amaury Forgeot d'Arc <[email protected]>
Branch:
Changeset: r62275:3e8a666e96f0
Date: 2013-03-10 15:51 +0100
http://bitbucket.org/pypy/pypy/changeset/3e8a666e96f0/
Log: Don't crash the interpreter when compiling an ast with invalid (non
increasing) line numbers
diff --git a/pypy/interpreter/astcompiler/assemble.py
b/pypy/interpreter/astcompiler/assemble.py
--- a/pypy/interpreter/astcompiler/assemble.py
+++ b/pypy/interpreter/astcompiler/assemble.py
@@ -424,7 +424,8 @@
if instr.lineno:
# compute deltas
line = instr.lineno - current_line
- assert line >= 0
+ if line < 0:
+ continue
addr = offset - current_off
# Python assumes that lineno always increases with
# increasing bytecode address (lnotab is unsigned char).
diff --git a/pypy/module/_ast/test/test_ast.py
b/pypy/module/_ast/test/test_ast.py
--- a/pypy/module/_ast/test/test_ast.py
+++ b/pypy/module/_ast/test/test_ast.py
@@ -314,3 +314,18 @@
ast.fix_missing_locations(m)
exc = raises(TypeError, compile, m, "<test>", "exec")
+ def test_hacked_lineno(self):
+ import _ast
+ stmt = '''if 1:
+ try:
+ foo
+ except Exception as error:
+ bar
+ except Baz as error:
+ bar
+ '''
+ mod = compile(stmt, "<test>", "exec", _ast.PyCF_ONLY_AST)
+ # These lineno are invalid, but should not crash the interpreter.
+ mod.body[0].body[0].handlers[0].lineno = 7
+ mod.body[0].body[0].handlers[1].lineno = 6
+ code = compile(mod, "<test>", "exec")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit