[geos-commits] [SCM] GEOS branch main updated. 108e59959d642977a5dc7e8cf20a7ac15561e837
git at osgeo.org
git at osgeo.org
Wed Jun 19 17:00:52 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 108e59959d642977a5dc7e8cf20a7ac15561e837 (commit)
via a02617f40778cc6a7165235a5219849dd6d5dd9d (commit)
via f03a3f3f576a28f7de4517cf3e0bcc0ec33a9487 (commit)
from a690eb66dcaf87f8bc5e1489c58123cc20cd179e (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 108e59959d642977a5dc7e8cf20a7ac15561e837
Author: Daniel Baston <dbaston at gmail.com>
Date: Wed Jun 19 19:57:24 2024 -0400
NEWS update
diff --git a/NEWS.md b/NEWS.md
index 2cc7944c7..b0a202231 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -37,6 +37,7 @@
- GEOSRelatePatternMatch: Fix crash on invalid DE-9IM pattern (GH-1089, Dan Baston)
- CoveragePolygonValidator: add section performance optimization (GH-1099, Martin Davis)
- TopologyPreservingSimplifier: fix to remove ring endpoints safely (GH-1110, Martin Davis)
+ - TopologyPreservingSimplifier: fix stack overflow on degenerate inputs (GH-1113, Dan Baston)
## Changes in 3.12.0
2023-06-27
commit a02617f40778cc6a7165235a5219849dd6d5dd9d
Author: Daniel Baston <dbaston at gmail.com>
Date: Wed Jun 19 13:37:03 2024 -0400
TopologyPreservingSimplifier: Avoid stack overflow on degenerate input
Fixes https://github.com/libgeos/geos/issues/1070
diff --git a/src/simplify/TaggedLineStringSimplifier.cpp b/src/simplify/TaggedLineStringSimplifier.cpp
index 04141bddb..842710ae8 100644
--- a/src/simplify/TaggedLineStringSimplifier.cpp
+++ b/src/simplify/TaggedLineStringSimplifier.cpp
@@ -144,6 +144,18 @@ TaggedLineStringSimplifier::simplifySection(std::size_t i,
<< std::endl;
#endif
+ if (distance < 0) {
+ // negative distance indicates that we could not compute distance to the
+ // farthest point, probably because of infinite or large-magnitude coordinates.
+ // avoid trying to simplify this section.
+ for (std::size_t k = i; k < j; k++) {
+ auto newSeg = std::make_unique<TaggedLineSegment>(*(line->getSegment(k)));
+ line->addToResult(std::move(newSeg));
+ }
+
+ return;
+ }
+
// flattening must be less than distanceTolerance
if(distance > distanceTolerance) {
isValidToSimplify = false;
diff --git a/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp b/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp
index 750858ebf..b257ad838 100644
--- a/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp
+++ b/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp
@@ -430,5 +430,17 @@ void object::test<33>()
"POLYGON ((-222618.41756525903 6299886.966175825, -222510 6300300, -221720.85158014414 6300132.680680807, -222448.77936063593 6299647.669870703, -222618.41756525903 6299886.966175825), (-222467.0202338936 6299970.185860572, -222456.57057590774 6299931.950053182, -222490.56062790897 6299837.359974515, -222415.1394852571 6299926.6972160805, -222421.19226152284 6299963.389132584, -222467.0202338936 6299970.185860572))");
}
+// https://github.com/libgeos/geos/issues/1070
+template<>
+template<>
+void object::test<34>()
+{
+ auto input = wktreader.read("MULTILINESTRING((0 0, 1 0001211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111, 1 00015111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111, 1 0001511111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111, 1 0, 10 01, 0 0))");
+
+ auto simplified = TopologyPreservingSimplifier::simplify(input.get(), 2.0);
+
+ ensure(simplified != nullptr); // no crash
+}
+
} // namespace tut
commit f03a3f3f576a28f7de4517cf3e0bcc0ec33a9487
Author: Daniel Baston <dbaston at gmail.com>
Date: Wed Jun 19 16:33:56 2024 -0400
LineSegmentIndex: Avoid creating std::vector on heap
diff --git a/include/geos/simplify/LineSegmentIndex.h b/include/geos/simplify/LineSegmentIndex.h
index 136d7bedb..3a8de122d 100644
--- a/include/geos/simplify/LineSegmentIndex.h
+++ b/include/geos/simplify/LineSegmentIndex.h
@@ -60,7 +60,7 @@ public:
void remove(const geom::LineSegment* seg);
- std::unique_ptr< std::vector<geom::LineSegment*> >
+ std::vector<const geom::LineSegment*>
query(const geom::LineSegment* seg);
diff --git a/src/simplify/LineSegmentIndex.cpp b/src/simplify/LineSegmentIndex.cpp
index 42b99e18a..7de458c1f 100644
--- a/src/simplify/LineSegmentIndex.cpp
+++ b/src/simplify/LineSegmentIndex.cpp
@@ -54,15 +54,14 @@ private:
const LineSegment* querySeg;
- std::unique_ptr< std::vector<LineSegment*> > items;
+ std::vector<const LineSegment*> items;
public:
LineSegmentVisitor(const LineSegment* s)
:
ItemVisitor(),
- querySeg(s),
- items(new std::vector<LineSegment*>())
+ querySeg(s)
{}
~LineSegmentVisitor() override
@@ -70,43 +69,23 @@ public:
// nothing to do, LineSegments are not owned by us
}
- LineSegmentVisitor(const LineSegmentVisitor& o)
- :
- ItemVisitor(),
- querySeg(o.querySeg),
- items(new std::vector<LineSegment*>(*(o.items.get())))
- {
- }
-
- LineSegmentVisitor&
- operator=(const LineSegmentVisitor& o)
- {
- if(this == &o) {
- return *this;
- }
- querySeg = o.querySeg;
- items.reset(new std::vector<LineSegment*>(*(o.items.get())));
- return *this;
- }
-
void
visitItem(void* item) override
{
- LineSegment* seg = static_cast<LineSegment*>(item);
+ const LineSegment* seg = static_cast<const LineSegment*>(item);
if(Envelope::intersects(seg->p0, seg->p1,
querySeg->p0, querySeg->p1)) {
- items->push_back(seg);
+ items.push_back(seg);
}
}
- std::unique_ptr< std::vector<LineSegment*> >
+ std::vector<const LineSegment*>
getItems()
{
// NOTE: Apparently, this is 'source' method giving up the object resource.
return std::move(items);
}
-
};
@@ -144,7 +123,7 @@ LineSegmentIndex::remove(const LineSegment* seg)
}
/*public*/
-std::unique_ptr< std::vector<LineSegment*> >
+std::vector<const LineSegment*>
LineSegmentIndex::query(const LineSegment* querySeg)
{
Envelope env(querySeg->p0, querySeg->p1);
@@ -152,7 +131,7 @@ LineSegmentIndex::query(const LineSegment* querySeg)
LineSegmentVisitor visitor(querySeg);
index.query(&env, visitor);
- std::unique_ptr< std::vector<LineSegment*> > itemsFound = visitor.getItems();
+ auto itemsFound = visitor.getItems();
return itemsFound;
}
diff --git a/src/simplify/TaggedLineStringSimplifier.cpp b/src/simplify/TaggedLineStringSimplifier.cpp
index b9d1cccc8..04141bddb 100644
--- a/src/simplify/TaggedLineStringSimplifier.cpp
+++ b/src/simplify/TaggedLineStringSimplifier.cpp
@@ -267,7 +267,7 @@ TaggedLineStringSimplifier::hasOutputIntersection(
//std::unique_ptr<std::vector<LineSegment*>>
auto querySegs = outputIndex->query(&flatSeg);
- for(const LineSegment* querySeg : *querySegs) {
+ for(const LineSegment* querySeg : querySegs) {
if(hasInvalidIntersection(*querySeg, flatSeg)) {
return true;
}
@@ -304,7 +304,7 @@ TaggedLineStringSimplifier::hasInputIntersection(
{
const auto& querySegs = inputIndex->query(&flatSeg);
- for(const LineSegment* ls : *querySegs) {
+ for(const LineSegment* ls : querySegs) {
const TaggedLineSegment* querySeg = static_cast<const TaggedLineSegment*>(ls);
if (hasInvalidIntersection(*ls, flatSeg)) {
-----------------------------------------------------------------------
Summary of changes:
NEWS.md | 1 +
include/geos/simplify/LineSegmentIndex.h | 2 +-
src/simplify/LineSegmentIndex.cpp | 35 +++++-----------------
src/simplify/TaggedLineStringSimplifier.cpp | 16 ++++++++--
.../simplify/TopologyPreservingSimplifierTest.cpp | 12 ++++++++
5 files changed, 35 insertions(+), 31 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list