Skip to content

Commit 8460386

Browse files
committed
Reject PyArray buffer with suboffsets
1 parent beec1ec commit 8460386

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/Wrap/PyArray.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ end
531531
function PyArraySource_Buffer(x::Py)
532532
memview = pybuiltins.memoryview(x)
533533
buf = C.UnsafePtr(C.PyMemoryView_GET_BUFFER(memview))
534+
buf.suboffsets[] == C_NULL ||
535+
error("PyArray does not support buffers with non-trivial suboffsets (PIL-style indirect layout)")
534536
PyArraySource_Buffer(x, memview, buf)
535537
end
536538

test/Wrap.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@
9191
end
9292
end
9393

94+
@testitem "PyArray buffer with suboffsets is rejected" begin
95+
tb = pyimport("_testbuffer")
96+
nd = tb.ndarray(
97+
pylist([1, 2, 3, 4, 5, 6]),
98+
shape = pylist([2, 3]),
99+
format = "i",
100+
flags = tb.ND_PIL | tb.ND_WRITABLE,
101+
)
102+
@test_throws Exception PyArray(nd; array = false, buffer = true)
103+
end
104+
94105
@testitem "PyDict" begin
95106
x = pydict(["foo" => 12])
96107
y = PyDict(x)

0 commit comments

Comments
 (0)