From 86ca4cbfb9a08348d2d3ba1359fee792ffa27dd5 Mon Sep 17 00:00:00 2001 From: Daniel Baston Date: Tue, 30 Apr 2024 18:37:19 -0400 Subject: [PATCH] IntersectionMatrix: Ignore patterns longer than 9 characters Fixes https://github.com/libgeos/geos/issues/1084 --- src/geom/IntersectionMatrix.cpp | 2 +- tests/unit/capi/GEOSRelatePatternMatchTest.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/geom/IntersectionMatrix.cpp b/src/geom/IntersectionMatrix.cpp index 82acfcf4ef..f7ace8a9e7 100644 --- a/src/geom/IntersectionMatrix.cpp +++ b/src/geom/IntersectionMatrix.cpp @@ -144,7 +144,7 @@ IntersectionMatrix::set(Location row, Location col, int dimensionValue) void IntersectionMatrix::set(const std::string& dimensionSymbols) { - auto limit = dimensionSymbols.length(); + auto limit = std::min(dimensionSymbols.length(), static_cast(9)); for(std::size_t i = 0; i < limit; i++) { auto row = i / firstDim; diff --git a/tests/unit/capi/GEOSRelatePatternMatchTest.cpp b/tests/unit/capi/GEOSRelatePatternMatchTest.cpp index c5f34a40b9..b60ab1e188 100644 --- a/tests/unit/capi/GEOSRelatePatternMatchTest.cpp +++ b/tests/unit/capi/GEOSRelatePatternMatchTest.cpp @@ -78,5 +78,18 @@ void object::test<5> ensure_equals(ret, char(0)); } +// invalid DE-9IM argument +// https://github.com/libgeos/geos/issues/1084 +template<> +template<> +void object::test<6> +() +{ + const char* mat = "0000000000"; + ensure_equals(strlen(mat), 10u); // not a valid DE-9IM! + + GEOSRelatePatternMatch(mat, "111111111"); +} + } // namespace tut