osm4j icon indicating copy to clipboard operation
osm4j copied to clipboard

While parsing a protocol message, the input ended unexpectedly in the middle of a field.

Open kkarski opened this issue 2 years ago • 5 comments

Hi, thanks for this library.

I am trying to parse country specific pbf files I downloaded from geofabric.de and consistently get the following error when parsing any of the country files (https://download.geofabrik.de/europe/belgium-latest.osm.pbf).

The code for parsing I am using is as follows:

final PbfIterator iterator = new PbfIterator(inputStream, false);
final InMemoryMapDataSet data = MapDataSetLoader.read(iterator, false, false, true);

I get the following error when reading into MapDataSetLoader

java.lang.RuntimeException: error while reading block
	at de.topobyte.osm4j.pbf.seq.PbfIterator.ensureBeyondBounds(PbfIterator.java:228)
	at de.topobyte.osm4j.pbf.seq.PbfIterator.hasBounds(PbfIterator.java:211)
	at de.topobyte.osm4j.core.dataset.MapDataSetLoader.read(MapDataSetLoader.java:78)
	at io.referential.data.OsmFileProcessor.main(OsmFileProcessor.java:143)
Caused by: com.google.protobuf.InvalidProtocolBufferException: While parsing a protocol message, the input ended unexpectedly in the middle of a field.  This could mean either that the input has been truncated or that an embedded message misreported its own length.
	at com.google.protobuf.InvalidProtocolBufferException.truncatedMessage(InvalidProtocolBufferException.java:107)
	at com.google.protobuf.GeneratedMessageLite.parsePartialFrom(GeneratedMessageLite.java:1584)
	at com.google.protobuf.GeneratedMessageLite.parseFrom(GeneratedMessageLite.java:1671)
	at de.topobyte.osm4j.pbf.protobuf.Fileformat$BlobHeader.parseFrom(Fileformat.java:1094)
	at de.topobyte.osm4j.pbf.util.PbfUtil.parseHeader(PbfUtil.java:92)
	at de.topobyte.osm4j.pbf.util.PbfUtil.parseHeader(PbfUtil.java:80)
	at de.topobyte.osm4j.pbf.seq.PbfIterator.advanceBlock(PbfIterator.java:129)
	at de.topobyte.osm4j.pbf.seq.PbfIterator.tryAdvanceBlock(PbfIterator.java:120)
	at de.topobyte.osm4j.pbf.seq.PbfIterator.ensureBeyondBounds(PbfIterator.java:226)
	... 3 common frames omitted

I am using osm4j-core, osm4j-pbf, osm4j-geometry 1.2.0.

kkarski avatar Nov 08 '22 12:11 kkarski