Skip to content

Commit cb414cf

Browse files
authored
bpo-45757: Fix bug where dis produced an incorrect oparg on EXTENDED_ARG before a no-arg opcode (GH-29480)
1 parent bcc4e46 commit cb414cf

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

Lib/dis.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ def _unpack_opargs(code):
523523
extended_arg = (arg << 8) if op == EXTENDED_ARG else 0
524524
else:
525525
arg = None
526+
extended_arg = 0
526527
yield (i, op, arg)
527528

528529
def findlabels(code):

Lib/test/test_dis.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,23 @@ def bug42562():
179179
2 RETURN_VALUE
180180
"""
181181

182+
# Extended arg followed by NOP
183+
code_bug_45757 = bytes([
184+
0x90, 0x01, # EXTENDED_ARG 0x01
185+
0x09, 0xFF, # NOP 0xFF
186+
0x90, 0x01, # EXTENDED_ARG 0x01
187+
0x64, 0x29, # LOAD_CONST 0x29
188+
0x53, 0x00, # RETURN_VALUE 0x00
189+
])
190+
191+
dis_bug_45757 = """\
192+
0 EXTENDED_ARG 1
193+
2 NOP
194+
4 EXTENDED_ARG 1
195+
6 LOAD_CONST 297
196+
8 RETURN_VALUE
197+
"""
198+
182199
_BIG_LINENO_FORMAT = """\
183200
%3d 0 LOAD_GLOBAL 0 (spam)
184201
2 POP_TOP
@@ -547,6 +564,10 @@ def test_bug_1333982(self):
547564
def test_bug_42562(self):
548565
self.do_disassembly_test(bug42562, dis_bug42562)
549566

567+
def test_bug_45757(self):
568+
# Extended arg followed by NOP
569+
self.do_disassembly_test(code_bug_45757, dis_bug_45757)
570+
550571
def test_big_linenos(self):
551572
def func(count):
552573
namespace = {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

0 commit comments

Comments
 (0)