-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Segfaults in ctypes _as_parameter_ handling when called with MagicMock
#127870
Labels
Comments
devdanzin
added
the
type-crash
A hard crash of the interpreter, possibly with a core dump
label
Dec 12, 2024
ctypes static PyObject *
c_char_p_from_param_impl(PyObject *type, PyTypeObject *cls, PyObject *value)
{
...
if (PyObject_GetOptionalAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
return NULL;
}
if (as_parameter) {
value = c_char_p_from_param_impl(type, cls, as_parameter);
Py_DECREF(as_parameter);
return value;
}
PyErr_Format(PyExc_TypeError,
"'%.200s' object cannot be interpreted "
"as ctypes.c_char_p", Py_TYPE(value)->tp_name);
return NULL;
} Getting Simpler reproducer: import ctypes.util
from unittest.mock import MagicMock
libc = ctypes.cdll.LoadLibrary("libc.so.6")
libc.strlen.argtypes = [ctypes.c_char_p]
libc.strlen.restype = ctypes.c_size_t
fake_str = MagicMock()
obj = libc.strlen(fake_str) |
vstinner
added
topic-ctypes
and removed
topic-repl
Related to the interactive shell
labels
Dec 12, 2024
vstinner
added a commit
to vstinner/cpython
that referenced
this issue
Dec 12, 2024
Detect recursive calls in ctypes _as_parameter_ handling: add Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() calls.
vstinner
changed the title
Segfaults in functions from
Segfaults in ctypes _as_parameter_ handling when called with Dec 12, 2024
_pyrepl._minimal_curses
when called with MagicMock
.MagicMock
vstinner
added a commit
to vstinner/cpython
that referenced
this issue
Dec 12, 2024
Detect recursive calls in ctypes _as_parameter_ handling: add Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() calls.
vstinner
added a commit
to vstinner/cpython
that referenced
this issue
Dec 12, 2024
Detect recursive calls in ctypes _as_parameter_ handling: add Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() calls.
I wrote #127872 to fix this issue. |
vstinner
added a commit
that referenced
this issue
Dec 13, 2024
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Dec 13, 2024
…ling (pythonGH-127872) (cherry picked from commit 6ff38fc) Co-authored-by: Victor Stinner <[email protected]>
vstinner
added a commit
to vstinner/cpython
that referenced
this issue
Dec 13, 2024
…ling (python#127872) (cherry picked from commit 6ff38fc)
vstinner
added a commit
to vstinner/cpython
that referenced
this issue
Dec 13, 2024
…ling (python#127872) (cherry picked from commit 6ff38fc)
Fixed, thanks for your bug report. |
srinivasreddy
pushed a commit
to srinivasreddy/cpython
that referenced
this issue
Jan 8, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Crash report
What happened?
It's possible to segfault the interpreter by calling any of the 3 functions below with
MagicMock
as argument. It takes a long time to trigger the crash (up to 3 minutes in my slow machine).The backtrace is very long, with over 87k entries in one case. Here's part of it:
I realize these functions are implemented with
ctypes
and internal to an internal package and hence this issue can be of very low importance. I just report in case they can point to some interesting related bug.Found using fusil by @vstinner.
CPython versions tested on:
3.13, 3.14, CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.13.1+ (heads/3.13:d51c1444e36, Dec 12 2024, 11:22:09) [GCC 11.4.0]
Linked PRs
The text was updated successfully, but these errors were encountered: