changeset 40998:89ceb93b1af5

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
author bpb
date Fri, 02 Sep 2016 11:29:02 -0700
parents b9a1c4fe2518
children a9586ec364da
files jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFDeflateDecompressor.java jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFLZWDecompressor.java
diffstat 2 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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;
 
+            int samplesPerRow = step * srcWidth;
+
+            int off = dstOffset + step;
             for (int j = 0; j < srcHeight; j++) {
-
-                int count = dstOffset + samplesPerPixel * (j * srcWidth + 1);
-
-                for (int i = samplesPerPixel; i < srcWidth * samplesPerPixel; i++) {
-
-                    dstData[count] += dstData[count - samplesPerPixel];
+                int count = off;
+                for (int i = step; i < samplesPerRow; i++) {
+                    dstData[count] += dstData[count - step];
                     count++;
                 }
+                off += samplesPerRow;
             }
         }