[geos-commits] [SCM] GEOS branch 3.8 updated. dfceb3487c2edcba75dac8a47c0153c6ee585305

git at osgeo.org git at osgeo.org
Fri Nov 6 11:31:13 PST 2020


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, 3.8 has been updated
       via  dfceb3487c2edcba75dac8a47c0153c6ee585305 (commit)
      from  17a2fedde5a24829790d495b259ce2986fa9f584 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit dfceb3487c2edcba75dac8a47c0153c6ee585305
Author: Sandro Santilli <strk at kbt.io>
Date:   Wed Sep 2 09:45:45 2020 -0400

    Fix segfault in SimplePointInAreaLocator
    
    Backport of patch by Oliver Tan
    
    Closes #1047 in 3.8 branch (3.8.2dev)
    References https://github.com/cockroachdb/cockroach/issues/53254

diff --git a/NEWS b/NEWS
index 4f789e0..b31aaf3 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ Changes in 3.8.2
 2020-xx-xx
 
 - Bug fixes / improvements
+
+  - Fix segfault in SimplePointInAreaLocator caused by casting
+    MultiPolygon to Polygon (#1047, Oliver Tan)
   - DistanceOp against geometry with empty components
     crashes (#1026, Paul Ramsey)
   - Remove undefined behaviour in CAPI (#1021, Greg Troxel)
diff --git a/src/algorithm/locate/SimplePointInAreaLocator.cpp b/src/algorithm/locate/SimplePointInAreaLocator.cpp
index 93e9482..399bab3 100644
--- a/src/algorithm/locate/SimplePointInAreaLocator.cpp
+++ b/src/algorithm/locate/SimplePointInAreaLocator.cpp
@@ -67,15 +67,17 @@ SimplePointInAreaLocator::locateInGeometry(const Coordinate& p, const Geometry*
     }
 
     if (geom->getNumGeometries() == 1) {
-        return locatePointInPolygon(p, dynamic_cast<const Polygon*>(geom->getGeometryN(0)));
-    } else {
-        for (size_t i = 0; i < geom->getNumGeometries(); i++) {
-            const Geometry* gi = geom->getGeometryN(i);
-
-            auto loc = locateInGeometry(p, gi);
-            if(loc != Location::EXTERIOR) {
-                return loc;
-            }
+        auto poly = dynamic_cast<const Polygon*>(geom->getGeometryN(0));
+        if (poly) {
+            return locatePointInPolygon(p, poly);
+        }
+        // Else it is a collection with a single element. Will be handled below.
+    }
+    for (size_t i = 0; i < geom->getNumGeometries(); i++) {
+        const Geometry* gi = geom->getGeometryN(i);
+        auto loc = locateInGeometry(p, gi);
+        if(loc != Location::EXTERIOR) {
+            return loc;
         }
     }
 
diff --git a/tests/unit/algorithm/PointLocatorTest.cpp b/tests/unit/algorithm/PointLocatorTest.cpp
index bc63b07..a230d96 100644
--- a/tests/unit/algorithm/PointLocatorTest.cpp
+++ b/tests/unit/algorithm/PointLocatorTest.cpp
@@ -5,6 +5,7 @@
 #include <tut/tut.hpp>
 // geos
 #include <geos/io/WKTReader.h>
+#include <geos/algorithm/locate/SimplePointInAreaLocator.h>
 #include <geos/algorithm/PointLocator.h>
 #include <geos/geom/PrecisionModel.h>
 #include <geos/geom/GeometryFactory.h>
@@ -56,6 +57,14 @@ runPtLocator(Location expected, const Coordinate& pt,
     ensure_equals(loc, expected);
 }
 
+void
+runSimplePtLocator(Location expected, const Coordinate& pt,
+             const std::string& wkt)
+{
+    GeomPtr geom(reader.read(wkt));
+    Location loc = geos::algorithm::locate::SimplePointInAreaLocator::locate(pt, geom.get());
+    ensure_equals(loc, expected);
+}
 
 //
 // Test Cases
@@ -111,5 +120,15 @@ void object::test<5>
                  "MULTIPOINT ((1 1), (0 0))");
 }
 
+// 6 - TestPointLocator Point inside GeometryCollection containing MultiPolygon, using SimplePointInAreaLocator.
+template<>
+template<>
+void object::test<6>
+()
+{
+    runSimplePtLocator(Location::INTERIOR, Coordinate(0, 0),
+                       "GEOMETRYCOLLECTION (MULTIPOLYGON (((-1 -1, 1 -1, 1 1, -1 1, -1 -1))))");
+}
+
 } // namespace tut
 

-----------------------------------------------------------------------

Summary of changes:
 NEWS                                              |  3 +++
 src/algorithm/locate/SimplePointInAreaLocator.cpp | 20 +++++++++++---------
 tests/unit/algorithm/PointLocatorTest.cpp         | 19 +++++++++++++++++++
 3 files changed, 33 insertions(+), 9 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list