From 84603866ab669b1f58cc1f5e315e233fa83cd6b6 Mon Sep 17 00:00:00 2001 From: nhz2 Date: Tue, 19 May 2026 13:53:23 -0400 Subject: [PATCH 1/3] Reject PyArray buffer with suboffsets --- src/Wrap/PyArray.jl | 2 ++ test/Wrap.jl | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/Wrap/PyArray.jl b/src/Wrap/PyArray.jl index 7b1dc8d3..dc11c085 100644 --- a/src/Wrap/PyArray.jl +++ b/src/Wrap/PyArray.jl @@ -531,6 +531,8 @@ end function PyArraySource_Buffer(x::Py) memview = pybuiltins.memoryview(x) buf = C.UnsafePtr(C.PyMemoryView_GET_BUFFER(memview)) + buf.suboffsets[] == C_NULL || + error("PyArray does not support buffers with non-trivial suboffsets (PIL-style indirect layout)") PyArraySource_Buffer(x, memview, buf) end diff --git a/test/Wrap.jl b/test/Wrap.jl index c42d45ab..5665003e 100644 --- a/test/Wrap.jl +++ b/test/Wrap.jl @@ -91,6 +91,17 @@ end end +@testitem "PyArray buffer with suboffsets is rejected" begin + tb = pyimport("_testbuffer") + nd = tb.ndarray( + pylist([1, 2, 3, 4, 5, 6]), + shape = pylist([2, 3]), + format = "i", + flags = tb.ND_PIL | tb.ND_WRITABLE, + ) + @test_throws Exception PyArray(nd; array = false, buffer = true) +end + @testitem "PyDict" begin x = pydict(["foo" => 12]) y = PyDict(x) From 858af7b0e85185eff8583488a6cb7dde4cd084ae Mon Sep 17 00:00:00 2001 From: Christopher Rowley Date: Sun, 24 May 2026 14:24:45 +0100 Subject: [PATCH 2/3] nest new test under existing PyArray testitem --- test/Wrap.jl | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/test/Wrap.jl b/test/Wrap.jl index 5665003e..09d6ece7 100644 --- a/test/Wrap.jl +++ b/test/Wrap.jl @@ -89,17 +89,16 @@ @test strides(y) == strides(y2) @test y == y2 end -end - -@testitem "PyArray buffer with suboffsets is rejected" begin - tb = pyimport("_testbuffer") - nd = tb.ndarray( - pylist([1, 2, 3, 4, 5, 6]), - shape = pylist([2, 3]), - format = "i", - flags = tb.ND_PIL | tb.ND_WRITABLE, - ) - @test_throws Exception PyArray(nd; array = false, buffer = true) + @testset "reject suboffsets (#775)" begin + tb = pyimport("_testbuffer") + nd = tb.ndarray( + pylist([1, 2, 3, 4, 5, 6]), + shape = pylist([2, 3]), + format = "i", + flags = tb.ND_PIL | tb.ND_WRITABLE, + ) + @test_throws Exception PyArray(nd; array = false, buffer = true) + end end @testitem "PyDict" begin From 87552cff806dd81369b9063fd8781edd4e69b9e3 Mon Sep 17 00:00:00 2001 From: Christopher Rowley Date: Sun, 24 May 2026 14:25:01 +0100 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1366eb2..0c414625 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## Unreleased +* Bug fixes. + ## 0.9.34 (2026-05-18) * Bug fixes.