From 237bcacd5b5049632092c800bb1a17958a97033a Mon Sep 17 00:00:00 2001 From: Dan Baston Date: Wed, 19 Jun 2024 21:07:40 -0400 Subject: [PATCH] GEOSConcaveHullOfPolygons: Avoid crash on zero-area input, references GH-1071 --- NEWS.md | 1 + src/algorithm/hull/ConcaveHullOfPolygons.cpp | 2 +- tests/unit/capi/GEOSConcaveHullOfPolygonsTest.cpp | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 6af7744e30..017a4e2c07 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ - GEOSLineSubstring: Fix crash on NaN length fractions (GH-1088, Dan Baston) - GEOSRelatePatternMatch: Fix crash on invalid DE-9IM pattern (GH-1089, Dan Baston) - Fix ConcaveHullOfPolygons nested shell handling (GH-1169, Martin Davis) + - GEOSConcaveHullOfPolygons, Avoid crash on zero-area input (GH-1071, Dan Baston) ## Changes in 3.12.2 2024-06-05 diff --git a/src/algorithm/hull/ConcaveHullOfPolygons.cpp b/src/algorithm/hull/ConcaveHullOfPolygons.cpp index 623a7662ab..d49b5eff1e 100644 --- a/src/algorithm/hull/ConcaveHullOfPolygons.cpp +++ b/src/algorithm/hull/ConcaveHullOfPolygons.cpp @@ -154,7 +154,7 @@ ConcaveHullOfPolygons::setTight(bool p_isTight) std::unique_ptr ConcaveHullOfPolygons::getHull() { - if (inputPolygons->isEmpty()) { + if (inputPolygons->isEmpty() || inputPolygons->getArea() == 0) { return createEmptyHull(); } buildHullTris(); diff --git a/tests/unit/capi/GEOSConcaveHullOfPolygonsTest.cpp b/tests/unit/capi/GEOSConcaveHullOfPolygonsTest.cpp index a5a485e9de..16a80299a0 100644 --- a/tests/unit/capi/GEOSConcaveHullOfPolygonsTest.cpp +++ b/tests/unit/capi/GEOSConcaveHullOfPolygonsTest.cpp @@ -54,6 +54,15 @@ void object::test<2>() ensure_geometry_equals(geom1_, expected_); } +template<> +template<> +void object::test<4>() +{ + input_ = fromWKT("POLYGON((0 0, 0 0, 0 0))"); + result_ = GEOSConcaveHullOfPolygons(input_, 0.7, false, false); + ensure(GEOSisEmpty(result_)); +} + } // namespace tut