Skip to content

pickle load_build function checks if state is None, not False #128965

Open
@Legoclones

Description

@Legoclones

Bug report

Bug description:

Inside of the load_build() function for pickle's BUILD opcode, the C accelerator at one point checks if state is Py_None, while the Python version only checks if state.

if (state != Py_None) {

if state:

This means if state is something like an empty dictionary or tuple, the code block under the if statement WILL be run in _pickle.c, but NOT in pickle.py.

As an example, the bytestream b']]b.' has the following disassembly:

    0: ]    EMPTY_LIST
    1: ]    EMPTY_LIST
    2: b    BUILD
    3: .    STOP
highest protocol among opcodes = 1

This will do nothing in pickle.py but error out in _pickle.c with the message state is not a dictionary. The easy solution is to change if state to if state != None, and it shouldn't break any existing functionality. I've attached a pull request.

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    • Status

      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions