8154075: [TIFF] AIOOB Exception from TIFFLZWDecompressor
Summary: For banded images make sure the step in the horizontal differencing predictor calculations for Deflate and LZW compression is unity (1) instead of the number of samples per pixel.
Reviewed-by: prr
--- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFDeflateDecompressor.java Fri Sep 02 10:48:35 2016 -0700
+++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFDeflateDecompressor.java Fri Sep 02 11:29:02 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -101,13 +101,17 @@
if (predictor ==
BaselineTIFFTagSet.PREDICTOR_HORIZONTAL_DIFFERENCING) {
+ int step = planar || samplesPerPixel == 1 ? 1 : samplesPerPixel;
+ int samplesPerRow = step * srcWidth;
+ int off = bufOffset + step;
for (int j = 0; j < srcHeight; j++) {
- int count = bufOffset + samplesPerPixel * (j * srcWidth + 1);
- for (int i=samplesPerPixel; i<srcWidth*samplesPerPixel; i++) {
- buf[count] += buf[count - samplesPerPixel];
+ int count = off;
+ for (int i = step; i < samplesPerRow; i++) {
+ buf[count] += buf[count - step];
count++;
}
+ off += samplesPerRow;
}
}
--- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFLZWDecompressor.java Fri Sep 02 10:48:35 2016 -0700
+++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFLZWDecompressor.java Fri Sep 02 11:29:02 2016 -0700
@@ -162,16 +162,18 @@
if (predictor ==
BaselineTIFFTagSet.PREDICTOR_HORIZONTAL_DIFFERENCING) {
+ int step = planar || samplesPerPixel == 1 ? 1 : samplesPerPixel;
- for (int j = 0; j < srcHeight; j++) {
+ int samplesPerRow = step * srcWidth;
- int count = dstOffset + samplesPerPixel * (j * srcWidth + 1);
-
- for (int i = samplesPerPixel; i < srcWidth * samplesPerPixel; i++) {
-
- dstData[count] += dstData[count - samplesPerPixel];
+ int off = dstOffset + step;
+ for (int j = 0; j < srcHeight; j++) {
+ int count = off;
+ for (int i = step; i < samplesPerRow; i++) {
+ dstData[count] += dstData[count - step];
count++;
}
+ off += samplesPerRow;
}
}