Skip to content

Commit

Permalink
8270952: Improve TIFF file handling
Browse files Browse the repository at this point in the history
Reviewed-by: mbaesken
Backport-of: 4db9acd53f549cac1603c6c41566b16ee939c04b
  • Loading branch information
Andrew Brygin authored and RealCLanger committed Jan 10, 2022
1 parent 883ecfe commit 6895d4a
Showing 1 changed file with 3 additions and 15 deletions.
Expand Up @@ -136,12 +136,7 @@ public void decodeRaw(byte[] b,

int lastRow = activeSrcHeight - 1;
for (int y = 0; y < activeSrcHeight; y++) {
int bytesRead = stream.read(b, dstOffset, activeBytesPerRow);
if (bytesRead < 0) {
throw new EOFException();
} else if (bytesRead != activeBytesPerRow) {
break;
}
stream.readFully(b, dstOffset, activeBytesPerRow);
dstOffset += scanlineStride;

// Skip unneeded bytes (row suffix + row prefix).
Expand All @@ -154,17 +149,10 @@ public void decodeRaw(byte[] b,
stream.seek(offset);
int bytesPerRow = (srcWidth*bitsPerPixel + 7)/8;
if(bytesPerRow == scanlineStride) {
if (stream.read(b, dstOffset, bytesPerRow*srcHeight) < 0) {
throw new EOFException();
}
stream.readFully(b, dstOffset, bytesPerRow*srcHeight);
} else {
for (int y = 0; y < srcHeight; y++) {
int bytesRead = stream.read(b, dstOffset, bytesPerRow);
if (bytesRead < 0) {
throw new EOFException();
} else if (bytesRead != bytesPerRow) {
break;
}
stream.readFully(b, dstOffset, bytesPerRow);
dstOffset += scanlineStride;
}
}
Expand Down

0 comments on commit 6895d4a

Please sign in to comment.