Skip to content

Commit a0e3810

Browse files
test: add test
1 parent 378edc6 commit a0e3810

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎test/test_memoryview.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,20 @@ def test_multidim_memoryview():
9797
data = view.cast(view.format, (3, 2))
9898
packed = packb(data)
9999
assert packed == b"\xc4\x06\x00\x00\x00\x00\x00\x00"
100+
101+
102+
def test_unpack_noncontiguous_memoryview():
103+
"""Non-contiguous strided memoryview triggers the contiguous-copy path in
104+
get_data_from_buffer. Before abffc45, Py_DECREF(contiguous) was called
105+
explicitly there, causing a double-decref when Cython also cleaned up the
106+
local on function exit; the backing buffer was freed before unpack_construct
107+
could read it. Run under ASan to catch the use-after-free."""
108+
# Use a multi-byte value so the padded stride-2 view is non-contiguous.
109+
packed = packb(2**32)
110+
padded = bytearray()
111+
for byte in packed:
112+
padded.append(byte)
113+
padded.append(0)
114+
noncont = memoryview(bytes(padded))[::2]
115+
assert not noncont.c_contiguous
116+
assert unpackb(noncont) == 2**32

0 commit comments

Comments
 (0)