Skip to content

Commit 6e15c6c

Browse files
authored
Fix segfault when coverage simplify called with nonpolygons, references GH-1031 (#1039)
1 parent 8d87edc commit 6e15c6c

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/coverage/CoverageSimplifier.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <geos/geom/Geometry.h>
2121
#include <geos/geom/GeometryFactory.h>
2222
#include <geos/geom/MultiLineString.h>
23+
#include <geos/util/IllegalArgumentException.h>
2324

2425

2526
using geos::geom::Geometry;
@@ -83,7 +84,12 @@ CoverageSimplifier::simplifyInner(
8384
CoverageSimplifier::CoverageSimplifier(std::vector<const Geometry*>& coverage)
8485
: m_input(coverage)
8586
, m_geomFactory(coverage.empty() ? nullptr : coverage[0]->getFactory())
86-
{}
87+
{
88+
for (const Geometry* g: m_input) {
89+
if (!g->isPolygonal())
90+
throw util::IllegalArgumentException("Argument is not a non-polygonal");
91+
}
92+
}
8793

8894
/* public */
8995
std::vector<std::unique_ptr<Geometry>>

tests/unit/coverage/CoverageSimplifierTest.cpp

+23-3
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ void object::test<24> ()
431431
"POLYGON EMPTY",
432432
"POLYGON EMPTY" })
433433
);
434-
}
434+
}
435435

436436
// testOneEmpty
437437
template<>
@@ -446,7 +446,7 @@ void object::test<25> ()
446446
"POLYGON ((1 9, 9 9, 9 1, 1 1, 1 9))",
447447
"POLYGON EMPTY" })
448448
);
449-
}
449+
}
450450

451451
// testEmptyHole()
452452
template<>
@@ -461,6 +461,26 @@ void object::test<26> ()
461461
"POLYGON ((1 9, 9 9, 9 1, 1 1, 1 9), EMPTY)",
462462
"POLYGON EMPTY" })
463463
);
464-
}
464+
}
465+
466+
// Test non-polygon inputs (GH-1031)
467+
template<>
468+
template<>
469+
void object::test<30> ()
470+
{
471+
auto input = readArray({
472+
"MULTILINESTRING ((200 100, 100 100, 200 200), (200 200, 200 100), (200 200, 300 100, 200 100))"
473+
});
474+
try {
475+
std::vector<std::unique_ptr<Geometry>> result =
476+
CoverageSimplifier::simplify(input, 10);
477+
}
478+
catch (geos::util::IllegalArgumentException& iae) {
479+
ensure("caught IllegalArgumentException", true);
480+
return;
481+
}
482+
ensure("did not throw IllegalArgumentException", false);
483+
}
484+
465485

466486
} // namespace tut

0 commit comments

Comments
 (0)