-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[BUG] Segfault in py::buffer::request on a ctypes array #2502
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
Comments
fritzr
added a commit
to fritzr/pybind11
that referenced
this issue
Sep 17, 2020
fritzr
added a commit
to fritzr/pybind11
that referenced
this issue
Sep 17, 2020
fritzr
added a commit
to fritzr/pybind11
that referenced
this issue
Sep 17, 2020
YannickJadoul
pushed a commit
that referenced
this issue
Oct 3, 2020
* tests: New test for ctypes buffers (#2502) * fix: fix buffer_info segfault on views with no stride (pybind11#2502) * Explicit conversions in buffer_info to make clang happy (#2502) * Another explicit cast in buffer_info constructor for clang (#2502) * Simpler implementation of buffer_info constructor from Py_buffer. * Move test_ctypes_buffer into test_buffers * Comment on why view->strides may be NULL (and fix some whitespace) * Use c_strides() instead of zero when view->strides is NULL. c_strides and f_strides are moved from numpy.h (py::array) to buffer_info.h (py::detail) so they can be used from the buffer_info Py_buffer constructor. * Increase ctypes buffer test coverage in test_buffers. * Split ctypes tests and skip one which is broken in PyPy2.
Fixed in #2503 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue description
py::buffer::request() causes a segmentation fault when attempting to get the py::buffer_info for a ctypes array in Python 2 because it has a NULL stride.
Reproducible example code
test_ctypes_buffer.cpp
test_ctypes_buffer.py
Segmentation fault:
$ g++ -dumpversion 7.4.0 $ g++ -g -O0 -Wall -shared -std=c++11 -fPIC `/usr/bin/python -m pybind11 --includes` test_ctypes_buffer.cpp -o test_ctypes_buffer.so $ /usr/bin/python -V Python 2.7.5 $ /usr/bin/python test_ctypes_buffer.py Segmentation fault (core dumped)
Post-mortem analysis:
We see that the ctypes array's buffer has NULL stride. Therefore the construction of
buffer_info::strides{NULL, NULL + view->ndim}
causes the segmentation fault.The text was updated successfully, but these errors were encountered: