Skip to content

[3.10] bpo-45757: Fix bug where dis produced an incorrect oparg on EXTENDED_ARG before a no-arg opcode (GH-29480) #29506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ def _unpack_opargs(code):
extended_arg = (arg << 8) if op == EXTENDED_ARG else 0
else:
arg = None
extended_arg = 0
yield (i, op, arg)

def findlabels(code):
Expand Down
21 changes: 21 additions & 0 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ def bug42562():
2 RETURN_VALUE
"""

# Extended arg followed by NOP
code_bug_45757 = bytes([
0x90, 0x01, # EXTENDED_ARG 0x01
0x09, 0xFF, # NOP 0xFF
0x90, 0x01, # EXTENDED_ARG 0x01
0x64, 0x29, # LOAD_CONST 0x29
0x53, 0x00, # RETURN_VALUE 0x00
])

dis_bug_45757 = """\
0 EXTENDED_ARG 1
2 NOP
4 EXTENDED_ARG 1
6 LOAD_CONST 297 (297)
8 RETURN_VALUE
"""

_BIG_LINENO_FORMAT = """\
%3d 0 LOAD_GLOBAL 0 (spam)
2 POP_TOP
Expand Down Expand Up @@ -534,6 +551,10 @@ def test_bug_1333982(self):
def test_bug_42562(self):
self.do_disassembly_test(bug42562, dis_bug42562)

def test_bug_45757(self):
# Extended arg followed by NOP
self.do_disassembly_test(code_bug_45757, dis_bug_45757)

def test_big_linenos(self):
def func(count):
namespace = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where :mod:`dis` produced an incorrect oparg when :opcode:`EXTENDED_ARG` is followed by an opcode that does not use its argument.