Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segfault when coverage simplify called with nonpolygons #1039

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading