Changeset 18702 in josm for trunk


Ignore:
Timestamp:
2023-04-11T19:04:13+02:00 (12 months ago)
Author:
taylor.smock
Message:

Fix #22868: NPE when a PBF does not include bound information

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/pbf/BlobHeader.java

    r18697 r18702  
    2727
    2828    /**
     29     * Get the blob type
    2930     * @return The blob type
    3031     */
     
    3435
    3536    /**
     37     * Get the blob metadata
    3638     * @return The blob metadata
    3739     */
     
    4143
    4244    /**
     45     * Get the blob size
    4346     * @return The blob size
    4447     */
  • trunk/src/org/openstreetmap/josm/data/osm/pbf/Info.java

    r18697 r18702  
    3636
    3737    /**
     38     * Get the OSM version
    3839     * @return The version
    3940     */
     
    4344
    4445    /**
     46     * Get the OSM timestamp
    4547     * @return The timestamp
    4648     */
     
    5052
    5153    /**
     54     * Get the OSM changeset
    5255     * @return The changeset
    5356     */
     
    5760
    5861    /**
     62     * Get the OSM user id
    5963     * @return The user id
    6064     */
     
    6468
    6569    /**
     70     * Get the id for the username in the PBF
    6671     * @return The user string id (in PBF strings)
    6772     */
     
    7176
    7277    /**
     78     * Get the visibility of the object
    7379     * @return {@code false} if the object was deleted
    7480     */
  • trunk/src/org/openstreetmap/josm/io/OsmPbfReader.java

    r18697 r18702  
    8686    }
    8787
    88     private DataSet parse(InputStream source) throws IllegalDataException, IOException {
     88    private void parse(InputStream source) throws IllegalDataException, IOException {
    8989        final CountingInputStream inputStream;
    9090        if (source.markSupported()) {
     
    119119            }
    120120        }
    121         return this.getDataSet();
    122121    }
    123122
     
    133132     */
    134133    @Nonnull
    135     private BlobHeader parseBlobHeader(CountingInputStream cis, ByteArrayOutputStream baos, ProtobufParser parser)
     134    private static BlobHeader parseBlobHeader(CountingInputStream cis, ByteArrayOutputStream baos, ProtobufParser parser)
    136135            throws IOException, IllegalDataException {
    137136        String type = null;
     
    181180     */
    182181    @Nonnull
    183     private Blob parseBlob(BlobHeader header, CountingInputStream cis, ProtobufParser parser, ByteArrayOutputStream baos) throws IOException {
     182    private static Blob parseBlob(BlobHeader header, CountingInputStream cis, ProtobufParser parser, ByteArrayOutputStream baos)
     183            throws IOException {
    184184        long start = cis.getBytesRead();
    185185        int size = Integer.MIN_VALUE;
     
    214214            }
    215215        }
     216        if (type == null) {
     217            throw new IllegalStateException("Compression type not found, pbf may be malformed");
     218        }
    216219        return new Blob(size, type, current.getBytes());
    217220    }
     
    226229     */
    227230    @Nonnull
    228     private HeaderBlock parseHeaderBlock(Blob blob, ByteArrayOutputStream baos) throws IOException {
     231    private static HeaderBlock parseHeaderBlock(Blob blob, ByteArrayOutputStream baos) throws IOException {
    229232        try (InputStream blobInput = blob.inputStream();
    230233             ProtobufParser parser = new ProtobufParser(blobInput)) {
     
    334337                dateGranularity);
    335338        final DataSet ds = getDataSet();
    336         if (!primitiveGroups.isEmpty()) {
     339        if (!primitiveGroups.isEmpty() && headerBlock.bbox() != null) {
    337340            try {
    338341                ds.beginUpdate();
     
    406409     */
    407410    @Nonnull
    408     private String[] parseStringTable(ByteArrayOutputStream baos, byte[] bytes) throws IOException {
     411    private static String[] parseStringTable(ByteArrayOutputStream baos, byte[] bytes) throws IOException {
    409412        try (ByteArrayInputStream is = new ByteArrayInputStream(bytes);
    410413             ProtobufParser parser = new ProtobufParser(is)) {
     
    681684     * @throws IOException          if something happened while reading a {@link ByteArrayInputStream}
    682685     */
    683     @Nonnull
    684686    private void parseRelation(ByteArrayOutputStream baos, byte[] bytes, PrimitiveBlockRecord primitiveBlockRecord)
    685687            throws IllegalDataException, IOException {
     
    758760     */
    759761    @Nonnull
    760     private Info parseInfo(ByteArrayOutputStream baos, byte[] bytes) throws IOException {
     762    private static Info parseInfo(ByteArrayOutputStream baos, byte[] bytes) throws IOException {
    761763        try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    762764             ProtobufParser parser = new ProtobufParser(bais)) {
     
    768770            boolean visible = true;
    769771            while (parser.hasNext()) {
    770                 ProtobufRecord record = new ProtobufRecord(baos, parser);
    771                 switch (record.getField()) {
     772                ProtobufRecord protobufRecord = new ProtobufRecord(baos, parser);
     773                switch (protobufRecord.getField()) {
    772774                    case 1:
    773                         version = record.asUnsignedVarInt().intValue();
     775                        version = protobufRecord.asUnsignedVarInt().intValue();
    774776                        break;
    775777                    case 2:
    776                         timestamp = record.asUnsignedVarInt().longValue();
     778                        timestamp = protobufRecord.asUnsignedVarInt().longValue();
    777779                        break;
    778780                    case 3:
    779                         changeset = record.asUnsignedVarInt().longValue();
     781                        changeset = protobufRecord.asUnsignedVarInt().longValue();
    780782                        break;
    781783                    case 4:
    782                         uid = record.asUnsignedVarInt().intValue();
     784                        uid = protobufRecord.asUnsignedVarInt().intValue();
    783785                        break;
    784786                    case 5:
    785                         userSid = record.asUnsignedVarInt().intValue();
     787                        userSid = protobufRecord.asUnsignedVarInt().intValue();
    786788                        break;
    787789                    case 6:
    788                         visible = record.asUnsignedVarInt().byteValue() == 0;
     790                        visible = protobufRecord.asUnsignedVarInt().byteValue() == 0;
    789791                        break;
    790792                    default: // Fall through, since the PBF format could be extended
     
    897899     */
    898900    @Nonnull
    899     private Info[] parseDenseInfo(ByteArrayOutputStream baos, byte[] bytes) throws IllegalDataException, IOException {
     901    private static Info[] parseDenseInfo(ByteArrayOutputStream baos, byte[] bytes) throws IllegalDataException, IOException {
    900902        long[] version = EMPTY_LONG; // technically ints
    901903        long[] timestamp = EMPTY_LONG;
Note: See TracChangeset for help on using the changeset viewer.