You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PyObject_CopyData() copies wrong data, and can corrupt memory, when source and destination shapes differ and the source is not contiguous #161081
I ran into this while writing tests for PyObject_CopyData() in GH-160701.
In the strided path of PyObject_CopyData() (Objects/abstract.c), the loop walks the source's indices and passes the same indices array to PyBuffer_GetPointer(&view_dest, ...). If the destination has a different shape, elements land at the wrong offsets. If it has more dimensions than the source, PyBuffer_GetPointer reads past the indices array.
Repro on 3.13.18 (numpy only to get a non-contiguous 2-D buffer; the code is unchanged on main):
I'd like to send a fix. Two options: raise BufferError when the shapes differ outside the contiguous fast path, or copy element-wise in C order with separate index walks for dest and src. Which would you prefer? gh-153689 touches the same function.
Activity
picnixz commentedon Nov 1, 2026
cc @encukou @ngoldbaum