8154075: [TIFF] AIOOB Exception from TIFFLZWDecompressor

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
This commit is contained in:
Brian Burkhalter 2016-09-02 11:29:02 -07:00
parent f0535f417c
commit 92cf16b425
2 changed files with 16 additions and 10 deletions

View File

@ -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 @@ public class TIFFDeflateDecompressor extends TIFFDecompressor {
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;
}
}

View File

@ -162,16 +162,18 @@ class TIFFLZWDecompressor extends TIFFDecompressor {
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;
}
}