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

Pickletools is too restrictive on STOP opcode #127079

Open
Legoclones opened this issue Nov 20, 2024 · 0 comments
Open

Pickletools is too restrictive on STOP opcode #127079

Legoclones opened this issue Nov 20, 2024 · 0 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@Legoclones
Copy link
Contributor

Legoclones commented Nov 20, 2024

Bug report

Bug description:

When the STOP opcode is encountered in pickletools, a check is made to see if there's anything left on the stack, and an error is thrown if there is.

cpython/Lib/pickletools.py

Lines 2542 to 2543 in 5414b97

if stack:
raise ValueError("stack not empty after STOP: %r" % stack)

However, both C and Python versions of the Unpickler don't make these checks and don't care how many items are left on the stack afterwards, as long as there's something for them to return.

In addition, C and Python versions of pickle don't care if a MARK opcode is still present or it's inside a metastack or whatnot, but since pickletools treats MARK as an object on the stack, it will also error out if a pickled bytestream like b'(K\x01.' is presented:

pickletools:  
    0: (    MARK
    1: K        BININT1    1
    3: .        STOP
highest protocol among opcodes = 1
pickletools failed stack not empty after STOP: [mark]

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Linked PRs

@Legoclones Legoclones added the type-bug An unexpected behavior, bug, or error label Nov 20, 2024
@picnixz picnixz added the stdlib Python modules in the Lib dir label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
Status: No status
Development

No branches or pull requests

2 participants