Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Calling _pickle.load with a MagicMock results in SystemError/aborts #126461

Closed
@devdanzin

Description

@devdanzin

Crash report

What happened?

Calling _pickle.load(MagicMock()) with a results in an abort in debug builds and a SystemError in non-debug.

In debug builds:

python -c "from unittest.mock import MagicMock as MM; from _pickle import load;
 load(MM())"
python: Objects/typeobject.c:5583: _PyType_LookupRef: Assertion `!PyErr_Occurred()' failed.
Aborted

In non-debug builds:

python -c "from unittest.mock import MagicMock as MM; from _pickle import load; load(MM())"
TypeError: a bytes-like object is required, not 'MagicMock'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    from unittest.mock import MagicMock as MM; from _pickle import load; load(MM())
                                                                         ~~~~^^^^^^
  File "/home/danzin/projects/cpython/Lib/unittest/mock.py", line 1168, in __call__
    self._mock_check_sig(*args, **kwargs)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
SystemError: <function CallableMixin._mock_check_sig at 0x7feb149cf8a0> returned a result with an exception set

Found using fusil by @vstinner.

CPython versions tested on:

3.13, 3.14, CPython main branch

Operating systems tested on:

Linux, Windows

Output from running 'python -VV' on the command line:

Python 3.14.0a1+ experimental free-threading build (heads/main-dirty:bfc1d2504c, Nov 4 2024, 07:55:58) [GCC 11.4.0]

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesextension-modulesC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions