Skip to content

Commit

Permalink
Fix segfault when coverage simplify called with nonpolygons, references
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Feb 5, 2024
1 parent 8d87edc commit 6e15c6c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/coverage/CoverageSimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <geos/geom/Geometry.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/MultiLineString.h>
#include <geos/util/IllegalArgumentException.h>


using geos::geom::Geometry;
Expand Down Expand Up @@ -83,7 +84,12 @@ CoverageSimplifier::simplifyInner(
CoverageSimplifier::CoverageSimplifier(std::vector<const Geometry*>& coverage)
: m_input(coverage)
, m_geomFactory(coverage.empty() ? nullptr : coverage[0]->getFactory())
{}
{
for (const Geometry* g: m_input) {
if (!g->isPolygonal())
throw util::IllegalArgumentException("Argument is not a non-polygonal");
}
}

/* public */
std::vector<std::unique_ptr<Geometry>>
Expand Down
26 changes: 23 additions & 3 deletions tests/unit/coverage/CoverageSimplifierTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ void object::test<24> ()
"POLYGON EMPTY",
"POLYGON EMPTY" })
);
}
}

// testOneEmpty
template<>
Expand All @@ -446,7 +446,7 @@ void object::test<25> ()
"POLYGON ((1 9, 9 9, 9 1, 1 1, 1 9))",
"POLYGON EMPTY" })
);
}
}

// testEmptyHole()
template<>
Expand All @@ -461,6 +461,26 @@ void object::test<26> ()
"POLYGON ((1 9, 9 9, 9 1, 1 1, 1 9), EMPTY)",
"POLYGON EMPTY" })
);
}
}

// Test non-polygon inputs (GH-1031)
template<>
template<>
void object::test<30> ()
{
auto input = readArray({
"MULTILINESTRING ((200 100, 100 100, 200 200), (200 200, 200 100), (200 200, 300 100, 200 100))"
});
try {
std::vector<std::unique_ptr<Geometry>> result =
CoverageSimplifier::simplify(input, 10);
}
catch (geos::util::IllegalArgumentException& iae) {
ensure("caught IllegalArgumentException", true);
return;
}
ensure("did not throw IllegalArgumentException", false);
}


} // namespace tut

0 comments on commit 6e15c6c

Please sign in to comment.