New submission from Thomas Wouters <tho...@python.org>:
The peephole optimizer in Python 2.7 and later (and probably a *lot* earlier) has a bug where if the optimizer entirely optimizes away the last line(s) of a function, the lnotab references invalid bytecode offsets: >>> def f(cond1, cond2): ... while 1: ... return 3 ... while 1: ... return 5 ... return 6 ... >>> list(dis.findlinestarts(f.__code__)) [(0, 3), (4, 5), (8, 6)] >>> len(f.__code__.co_code) 8 >>> f.__code__.co_code[8] Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: index out of range The problem is that the lnotab-readjustment in Python/peephole.c doesn't account for trailing NOPs in a bytecode string. I haven't been able to reproduce this before Python 3.8, probably because the optimizer wasn't capable of optimizing things aggressively enough to end a bytecode string with NOPs. I have a fix for this bug already. ---------- assignee: twouters components: Interpreter Core keywords: patch messages: 351902 nosy: lukasz.langa, pablogsal, twouters priority: release blocker severity: normal status: open title: Invalid bytecode offsets in co_lnotab type: behavior versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38115> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com