Skip to content

Commit

Permalink
Fix bounds check on dense nodes (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry authored Jul 20, 2022
1 parent c6ad30c commit 0e63940
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,11 @@ public OsmElement.Node next() {
int version = 0;

if (denseInfo != null) {
version = denseInfo.getVersion(i);
timestamp += denseInfo.getTimestamp(i);
changeset += denseInfo.getChangeset(i);
uid += denseInfo.getUid(i);
userSid += denseInfo.getUserSid(i);
version = denseInfo.getVersionCount() > i ? denseInfo.getVersion(i) : 0;
timestamp += denseInfo.getTimestampCount() > i ? denseInfo.getTimestamp(i) : 0;
changeset += denseInfo.getChangesetCount() > i ? denseInfo.getChangeset(i) : 0;
uid += denseInfo.getUidCount() > i ? denseInfo.getUid(i) : 0;
userSid += denseInfo.getUserSidCount() > i ? denseInfo.getUserSid(i) : 0;
}

i++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,49 @@ void testReadMonacoTwice(boolean lazy) {
}
}
}

@ParameterizedTest
@ValueSource(booleans = {false, true})
@Timeout(30)
void testReadMonacoWithoutChangesetsTwice(boolean lazy) {
for (int i = 1; i <= 2; i++) {
AtomicInteger nodes = new AtomicInteger(0);
AtomicInteger ways = new AtomicInteger(0);
AtomicInteger rels = new AtomicInteger(0);
AtomicReference<OsmElement.Node> node = new AtomicReference<>();
AtomicReference<OsmElement.Way> way = new AtomicReference<>();
AtomicReference<OsmElement.Relation> rel = new AtomicReference<>();
var file = new OsmInputFile(TestUtils.pathToResource("monaco-latest-without-changesets.osm.pbf"), lazy);
try (var osmReader = file.get()) {
WorkerPipeline.start("test", Stats.inMemory())
.fromGenerator("pbf", osmReader::forEachBlock)
.addBuffer("pbf_blocks", 100)
.sinkToConsumer("counter", 1, block -> {
for (var elem : block.decodeElements()) {
if (elem instanceof OsmElement.Node n) {
if (n.id() == expectedNode.id()) {
node.set(n);
}
nodes.incrementAndGet();
} else if (elem instanceof OsmElement.Way w) {
if (w.id() == expectedWay.id()) {
way.set(w);
}
ways.incrementAndGet();
} else if (elem instanceof OsmElement.Relation r) {
if (r.id() == expectedRel.id()) {
rel.set(r);
}
rels.incrementAndGet();
}
}
}).await();
assertEquals(27_135, nodes.get(), "nodes pass " + i);
assertEquals(4_295, ways.get(), "ways pass " + i);
assertEquals(255, rels.get(), "rels pass " + i);

assertEquals(new OsmElement.Info(0, 1647347498, 0, 8, ""), node.get().info());
}
}
}
}
Binary file not shown.

0 comments on commit 0e63940

Please sign in to comment.