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 crash while building geometry of multipolygon with zero-node way members #529

Merged
merged 1 commit into from
Jun 25, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Changelog

## 1.3.0-SNAPSHOT (current main)

### bugfixes

* Fix crash while building geometry of multipolygon with zero-node way members under certain circumstances


## 1.2.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,9 @@ private static List<LinkedList<OSMNode>> buildRings(
joinable = false;
for (var waysIterator = ways.iterator(); waysIterator.hasNext();) {
LinkedList<OSMNode> what = waysIterator.next();
if (what.isEmpty()) {
continue;
}
if (lastId == what.getFirst().getId()) {
// end of partial ring matches to start of current line
what.removeFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.heigit.ohsome.oshdb.OSHDBTimestamp;
import org.heigit.ohsome.oshdb.osm.OSMRelation;
import org.heigit.ohsome.oshdb.util.geometry.OSHDBGeometryBuilder;
import org.heigit.ohsome.oshdb.util.geometry.OSHDBGeometryTest;
import org.heigit.ohsome.oshdb.util.geometry.helpers.TimestampParser;
Expand Down Expand Up @@ -69,4 +70,14 @@ void testAllNodesOfWayNotExistent() {
Geometry result = buildGeometry(relations(502L, 0), timestamp);
assertNotNull(result);
}

@Test
void testRelationMemberWayWithoutNodes() {
// ways without nodes references (=invalid OSM data) can occur in old OSM data
// example: https://www.openstreetmap.org/api/0.6/way/25714579/6
OSMRelation rel = relations(503L, 0);
Geometry result = buildGeometry(rel);
// no exception should have been thrown at this point
assertTrue(result.isValid());
}
}
25 changes: 9 additions & 16 deletions oshdb-util/src/test/resources/incomplete-osm/polygon.osm
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@
<node id="21" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.34" lat="1.05"/>
<node id="22" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.32" lat="1.05"/>
<node id="23" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.32" lat="1.04"/>

<node id="24" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.31" lat="1.04"/>
<node id="25" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.33" lat="1.05"/>
<node id="26" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.33" lat="1.04"/>
<node id="27" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.32" lat="1.04"/>

<node id="28" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.31" lat="1.01"/>
<way id="102" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<nd ref="11"/>
<nd ref="12"/>
<nd ref="13"/>
<tag k="test:section" v="mp-geom"/>
<tag k="test:id" v="703"/>
</way>
<way id="103" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<nd ref="13"/>
Expand All @@ -31,8 +27,6 @@
<nd ref="17"/>
<nd ref="18"/>
<nd ref="11"/>
<tag k="test:section" v="mp-geom"/>
<tag k="test:id" v="703"/>
</way>
<way id="105" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<nd ref="24"/>
Expand All @@ -41,36 +35,35 @@
<nd ref="27"/>
<nd ref="28"/>
<nd ref="24"/>
<tag k="test:section" v="mp-geom"/>
<tag k="test:id" v="703"/>
</way>
<way id="106" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<nd ref="1"/>
<nd ref="2"/>
<tag k="test:section" v="mp-geom"/>
<tag k="test:id" v="731"/>
</way>
<way id="107" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
</way>
<relation id="500" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<member type="way" ref="102" role="outer"/>
<member type="way" ref="103" role="outer"/>
<tag k="type" v="multipolygon"/>
<tag k="test:section" v="mp-geom"/>
<tag k="test:id" v="703"/>
<tag k="landuse" v="forest"/>
</relation>
<relation id="501" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<member type="way" ref="104" role="outer"/>
<member type="way" ref="105" role="outer"/>
<tag k="type" v="multipolygon"/>
<tag k="test:section" v="mp-geom"/>
<tag k="test:id" v="703"/>
<tag k="landuse" v="forest"/>
</relation>
<relation id="502" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<member type="way" ref="106" role="outer"/>
<tag k="type" v="multipolygon"/>
<tag k="test:section" v="mp-geom"/>
<tag k="test:id" v="703"/>
<tag k="landuse" v="forest"/>
</relation>
<relation id="503" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<member type="way" ref="102" role="outer"/>
<member type="way" ref="107" role="outer"/>
<member type="way" ref="103" role="outer"/>
<tag k="type" v="multipolygon"/>
<tag k="landuse" v="forest"/>
</relation>
</osm>