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

iritkatriel webhook-mailer at python.org
Tue Nov 9 15:07:46 EST 2021


https://github.com/python/cpython/commit/cb414cf0e207668300c4fe3f310c0bd249153273
commit: cb414cf0e207668300c4fe3f310c0bd249153273
branch: main
author: Irit Katriel <1055913+iritkatriel at users.noreply.github.com>
committer: iritkatriel <1055913+iritkatriel at users.noreply.github.com>
date: 2021-11-09T20:07:38Z
summary:

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

files:
A Misc/NEWS.d/next/Library/2021-11-08-23-22-14.bpo-45757.MHZHt3.rst
M Lib/dis.py
M Lib/test/test_dis.py

diff --git a/Lib/dis.py b/Lib/dis.py
index 54275648fbb4b..8b429b5b72522 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -523,6 +523,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):
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 2a0e3b4e84981..fad2d06f928fe 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -179,6 +179,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
+          8 RETURN_VALUE
+"""
+
 _BIG_LINENO_FORMAT = """\
 %3d           0 LOAD_GLOBAL              0 (spam)
               2 POP_TOP
@@ -547,6 +564,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 = {}
diff --git a/Misc/NEWS.d/next/Library/2021-11-08-23-22-14.bpo-45757.MHZHt3.rst b/Misc/NEWS.d/next/Library/2021-11-08-23-22-14.bpo-45757.MHZHt3.rst
new file mode 100644
index 0000000000000..f25638cc68f85
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-11-08-23-22-14.bpo-45757.MHZHt3.rst
@@ -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.
\ No newline at end of file



More information about the Python-checkins mailing list