Changeset 19024 in josm


Ignore:
Timestamp:
2024-04-02T18:57:56+02:00 (5 weeks ago)
Author:
taylor.smock
Message:

Fix #23550: Error when deserializing PBF Blog (patch by giora.kosoi, modified)

Modifications are as follows:

  • Added non-regression test
  • Removed unnecessary changes in Blob
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmPbfReader.java

    r18877 r19024  
    185185        int size = Integer.MIN_VALUE;
    186186        Blob.CompressionType type = null;
    187         ProtobufRecord current = null;
     187        ProtobufRecord current;
     188        // Needed since size and compression type + compression data may be in a different order
     189        byte [] bytes = null;
    188190        while (parser.hasNext() && cis.getBytesRead() - start < header.dataSize()) {
    189191            current = new ProtobufRecord(baos, parser);
     
    191193                case 1:
    192194                    type = Blob.CompressionType.raw;
     195                    bytes = current.getBytes();
    193196                    break;
    194197                case 2:
     
    197200                case 3:
    198201                    type = Blob.CompressionType.zlib;
     202                    bytes = current.getBytes();
    199203                    break;
    200204                case 4:
    201205                    type = Blob.CompressionType.lzma;
     206                    bytes = current.getBytes();
    202207                    break;
    203208                case 5:
    204209                    type = Blob.CompressionType.bzip2;
     210                    bytes = current.getBytes();
    205211                    break;
    206212                case 6:
    207213                    type = Blob.CompressionType.lz4;
     214                    bytes = current.getBytes();
    208215                    break;
    209216                case 7:
    210217                    type = Blob.CompressionType.zstd;
     218                    bytes = current.getBytes();
    211219                    break;
    212220                default:
     
    217225            throw new IllegalStateException("Compression type not found, pbf may be malformed");
    218226        }
    219         return new Blob(size, type, current.getBytes());
     227        return new Blob(size, type, bytes);
    220228    }
    221229
  • trunk/test/unit/org/openstreetmap/josm/gui/io/importexport/OsmPbfImporterTest.java

    r18828 r19024  
    143143        assertNotNull(dataSet.getPrimitiveById(9223372036854775806L, OsmPrimitiveType.RELATION));
    144144    }
     145
     146    /**
     147     * Non-regression test for #23550: Error when deserializing PBF blob when generator writes the blob <i>then</i>
     148     * the compression type.
     149     */
     150    @Test
     151    void testNonRegression23550() {
     152        final byte[] badData = HEADER_DATA.clone();
     153        final byte[] sizeInfo = Arrays.copyOfRange(badData, 18, 21);
     154        for (int i = 18; i < badData.length - sizeInfo.length; i++) {
     155            badData[i] = badData[i + sizeInfo.length];
     156        }
     157        System.arraycopy(sizeInfo, 0, badData, badData.length - 3, 3);
     158        // the data doesn't include any "real" data, but the problematic code path is exercised by the header parsing code.
     159        assertDoesNotThrow(() -> importer.parseDataSet(new ByteArrayInputStream(badData), NullProgressMonitor.INSTANCE));
     160    }
    145161}
Note: See TracChangeset for help on using the changeset viewer.