[geos-commits] [SCM] GEOS branch main updated. a32469b222c1f0bae5d9e596340a664127142446

git at osgeo.org git at osgeo.org
Wed May 15 06:01:29 PDT 2024


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, main has been updated
       via  a32469b222c1f0bae5d9e596340a664127142446 (commit)
      from  7f429a927aa7638a2087a59f62a5f67fe1d094a2 (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 a32469b222c1f0bae5d9e596340a664127142446
Author: Dan Baston <dbaston at gmail.com>
Date:   Wed May 15 09:01:06 2024 -0400

    GEOSLineSubstring: Avoid crash with NaN length fraction (#1088)
    
    * GEOSLineSubstring: Avoid crash with NaN length fraction
    
    Fixes https://github.com/libgeos/geos/issues/1077
    
    * GEOSLineSubstring: Add test for non-linear input

diff --git a/src/linearref/LengthIndexedLine.cpp b/src/linearref/LengthIndexedLine.cpp
index 012a9dc43..5522eb32c 100644
--- a/src/linearref/LengthIndexedLine.cpp
+++ b/src/linearref/LengthIndexedLine.cpp
@@ -57,6 +57,13 @@ LengthIndexedLine::extractPoint(double index, double offsetDistance) const
 std::unique_ptr<Geometry>
 LengthIndexedLine::extractLine(double startIndex, double endIndex) const
 {
+    if (std::isnan(startIndex)) {
+        throw util::IllegalArgumentException("startIndex is NaN");
+    }
+    if (std::isnan(endIndex)) {
+        throw util::IllegalArgumentException("endIndex is NaN");
+    }
+
     const LocationIndexedLine lil(linearGeom);
     const double startIndex2 = clampIndex(startIndex);
     const double endIndex2 = clampIndex(endIndex);
diff --git a/tests/unit/capi/GEOSInterpolateTest.cpp b/tests/unit/capi/GEOSInterpolateTest.cpp
index 3b5a49f60..44992617f 100644
--- a/tests/unit/capi/GEOSInterpolateTest.cpp
+++ b/tests/unit/capi/GEOSInterpolateTest.cpp
@@ -72,4 +72,14 @@ void object::test<4>
     ensure_geometry_equals(result_, expected_);
 }
 
+// ensure NaN argument does not crash
+template<>
+template<>
+void object::test<5>
+()
+{
+    geom1_ = GEOSGeomFromWKT("LINESTRING (0 0, 1 1)");
+    result_ = GEOSInterpolate(geom1_, std::numeric_limits<double>::quiet_NaN());
+}
+
 } // namespace tut
diff --git a/tests/unit/capi/GEOSLineSubstringTest.cpp b/tests/unit/capi/GEOSLineSubstringTest.cpp
index 24078c085..df79b2659 100644
--- a/tests/unit/capi/GEOSLineSubstringTest.cpp
+++ b/tests/unit/capi/GEOSLineSubstringTest.cpp
@@ -131,5 +131,31 @@ void object::test<7>()
     ensure("curved geometries not supported", result_ == nullptr);
 }
 
+// NaN start fraction
+// https://github.com/libgeos/geos/issues/1077
+template<>
+template<>
+void object::test<8>
+()
+{
+    input_ = fromWKT("LINESTRING EMPTY");
+    double start = std::numeric_limits<double>::quiet_NaN();
+    double end = 0.1;
+    result_ = GEOSLineSubstring(input_, start, end);
+
+    ensure(result_ == nullptr);
+}
+
+template<>
+template<>
+void object::test<9>
+()
+{
+    input_ = fromWKT("POLYGON ((0 0, 1 0, 1 1, 0 0))");
+    result_ = GEOSLineSubstring(input_, 0.2, 0.3);
+
+    ensure(result_ == nullptr);
+}
+
 } // namespace tut
 

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

Summary of changes:
 src/linearref/LengthIndexedLine.cpp       |  7 +++++++
 tests/unit/capi/GEOSInterpolateTest.cpp   | 10 ++++++++++
 tests/unit/capi/GEOSLineSubstringTest.cpp | 26 ++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list