Skip to content

Commit c100886

Browse files
authored
Merge pull request scipy#20633 from tylerjereddy/treddy_issue_20623_spatial
BUG: fix Vor/Delaunay segfaults
2 parents 75fb00d + bec9c7d commit c100886

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

scipy/spatial/_qhull.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,8 @@ class Delaunay(_QhullUser):
18021802
if np.ma.isMaskedArray(points):
18031803
raise ValueError('Input points cannot be a masked array')
18041804
points = np.ascontiguousarray(points, dtype=np.double)
1805+
if points.ndim != 2:
1806+
raise ValueError("Input points array must have 2 dimensions.")
18051807

18061808
if qhull_options is None:
18071809
if not incremental:
@@ -2592,6 +2594,8 @@ class Voronoi(_QhullUser):
25922594
if np.ma.isMaskedArray(points):
25932595
raise ValueError('Input points cannot be a masked array')
25942596
points = np.ascontiguousarray(points, dtype=np.double)
2597+
if points.ndim != 2:
2598+
raise ValueError("Input points array must have 2 dimensions.")
25952599

25962600
if qhull_options is None:
25972601
if not incremental:

scipy/spatial/tests/test_qhull.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,3 +1178,11 @@ def test_cube(self):
11781178
assert set(a) == set(b) # facet orientation can differ
11791179

11801180
assert_allclose(hs.dual_points, qhalf_points)
1181+
1182+
1183+
@pytest.mark.parametrize("diagram_type", [Voronoi, qhull.Delaunay])
1184+
def test_gh_20623(diagram_type):
1185+
rng = np.random.default_rng(123)
1186+
invalid_data = rng.random((4, 10, 3))
1187+
with pytest.raises(ValueError, match="dimensions"):
1188+
diagram_type(invalid_data)

0 commit comments

Comments
 (0)