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

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

Closed
devdanzin opened this issue Nov 5, 2024 · 1 comment
Closed

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

devdanzin opened this issue Nov 5, 2024 · 1 comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@devdanzin
Copy link
Contributor

devdanzin commented Nov 5, 2024

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

@devdanzin devdanzin added the type-crash A hard crash of the interpreter, possibly with a core dump label Nov 5, 2024
vstinner added a commit to vstinner/cpython that referenced this issue Nov 6, 2024
Handle _Unpickler_SetStringInput() failure.
@ZeroIntensity ZeroIntensity added extension-modules C modules in the Modules dir 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Nov 6, 2024
vstinner added a commit that referenced this issue Nov 6, 2024
Handle _Unpickler_SetStringInput() failure.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 6, 2024
…GH-126485)

Handle _Unpickler_SetStringInput() failure.
(cherry picked from commit a1c57bc)

Co-authored-by: Victor Stinner <vstinner@python.org>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 6, 2024
…GH-126485)

Handle _Unpickler_SetStringInput() failure.
(cherry picked from commit a1c57bc)

Co-authored-by: Victor Stinner <vstinner@python.org>
@vstinner
Copy link
Member

vstinner commented Nov 6, 2024

Fixed. Thanks for your bug report.

@vstinner vstinner closed this as completed Nov 6, 2024
vstinner added a commit that referenced this issue Nov 6, 2024
…6485) (#126496)

gh-126461: Fix _Unpickler_ReadFromFile() error handling (GH-126485)

Handle _Unpickler_SetStringInput() failure.
(cherry picked from commit a1c57bc)

Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit that referenced this issue Nov 6, 2024
…6485) (#126495)

gh-126461: Fix _Unpickler_ReadFromFile() error handling (GH-126485)

Handle _Unpickler_SetStringInput() failure.
(cherry picked from commit a1c57bc)

Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump
Projects
Status: Done
Development

No branches or pull requests

3 participants