GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — PyObject_CopyData() copies wrong data, and can corrupt memory, when source and destination shapes differ and the source is not contiguous · Issue #161081 · python/cpython Open Labels interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug reportI 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): import ctypes, numpy as np f = ctypes.pythonapi.PyObject_CopyData f.argtypes = [ctypes.py_object, ctypes.py_object] src = np.arange(12, dtype=np.uint8).reshape(3, 4)[::2, ::2] dest = bytearray(4) print(f(dest, src), list(dest)) # 0 [0, 10, 0, 0], expected [0, 2, 8, 10] dest = np.zeros((2, 4), np.uint8) f(dest, memoryview(bytes(range(16)))[::2]) # returns 0, wrong data, then segfaults at exit 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. CPython versions tested on:3.13 Operating systems tested on:Linux Linked PRsActivity
MetadataMetadataAssigneesLabelsinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |