Skip to content

Commit

Permalink
Avoid reading unused bytes from PNG streams (#535)
Browse files Browse the repository at this point in the history
Co-authored-by: Milan Nikl <[email protected]>
  • Loading branch information
Draczech and Draczech authored May 4, 2021
1 parent 65b2752 commit d56b5a5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Source/com/drew/imaging/png/PngChunkReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public Iterable<PngChunk> extract(@NotNull final SequentialReader reader, @Nulla
// Miscellaneous information: bKGD, hIST, pHYs, sPLT
// Time information: tIME
//
// CHUNK READING
//
// Only chunk data for types specified in desiredChunkTypes is extracted.
// For empty chunk type list NO data is copied from source stream.
// For null chunk type list ALL data is copied from source stream.
//

reader.setMotorolaByteOrder(true); // network byte order

Expand All @@ -93,7 +99,13 @@ public Iterable<PngChunk> extract(@NotNull final SequentialReader reader, @Nulla

boolean willStoreChunk = desiredChunkTypes == null || desiredChunkTypes.contains(chunkType);

byte[] chunkData = reader.getBytes(chunkDataLength);
byte[] chunkData;
if (willStoreChunk) {
chunkData = reader.getBytes(chunkDataLength);
} else {
chunkData = null; // To satisfy the compiler
reader.skip(chunkDataLength);
}

// Skip the CRC bytes at the end of the chunk
// TODO consider verifying the CRC value to determine if we're processing bad data
Expand Down

0 comments on commit d56b5a5

Please sign in to comment.