Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid reading unused bytes from PNG streams #535

Merged
merged 4 commits into from
May 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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