Skip to content
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

dis._unpack_opargs should handle EXTENDED_ARG_QUICK #92932

Closed
colesbury opened this issue May 18, 2022 · 0 comments · Fixed by #92945
Closed

dis._unpack_opargs should handle EXTENDED_ARG_QUICK #92932

colesbury opened this issue May 18, 2022 · 0 comments · Fixed by #92945
Labels
3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@colesbury
Copy link
Contributor

colesbury commented May 18, 2022

In Python 3.11b0, dis.dis() and dis.get_instructions() will show the "wrong" operand values for instructions prefixed by EXTENDED_ARG_QUICK.

cpython/Lib/dis.py

Lines 591 to 595 in a4460f2

deop = _deoptop(op)
caches = _inline_cache_entries[deop]
if deop >= HAVE_ARGUMENT:
arg = code[i+1] | extended_arg
extended_arg = (arg << 8) if op == EXTENDED_ARG else 0

The bug is that this line only checks for EXTENDED_ARG instructions. It should check for instructions that deoptimize to EXTENDED_ARG (i.e. deop == EXTENDED_ARG).

extended_arg = (arg << 8) if op == EXTENDED_ARG else 0

To reproduce the issue, consider this snippet adapted from cloudpickle:

import random
import textwrap
import dis

nvars = 65537 + 258
names = ['g%d' % i for i in range(1, nvars)]
r = random.Random(42)
d = {name: r.randrange(100) for name in names}
# def f(x):
#     x = g1, g2, ...
code = """
def f():
    x = {tup}
""".format(tup=', '.join(names))
exec(textwrap.dedent(code), d, d)
f = d['f']

dis.dis(f)
@colesbury colesbury added type-bug An unexpected behavior, bug, or error 3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir labels May 18, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 3, 2022
…ythongh-92945)

(cherry picked from commit b013804)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
miss-islington added a commit that referenced this issue Jun 3, 2022
(cherry picked from commit b013804)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant