8011248: Better Component Rasters

Reviewed-by: bae, vadim, mschoene
This commit is contained in:
Phil Race 2013-04-08 13:29:19 -07:00
parent 60bb493c66
commit 6a20e4d507

View File

@ -654,9 +654,6 @@ public class IntegerComponentRaster extends SunWritableRaster {
") must be >= 0"); ") must be >= 0");
} }
int maxSize = 0;
int size;
// we can be sure that width and height are greater than 0 // we can be sure that width and height are greater than 0
if (scanlineStride < 0 || if (scanlineStride < 0 ||
scanlineStride > (Integer.MAX_VALUE / height)) scanlineStride > (Integer.MAX_VALUE / height))
@ -682,21 +679,23 @@ public class IntegerComponentRaster extends SunWritableRaster {
} }
lastPixelOffset += lastScanOffset; lastPixelOffset += lastScanOffset;
int index;
int maxIndex = 0;
for (int i = 0; i < numDataElements; i++) { for (int i = 0; i < numDataElements; i++) {
if (dataOffsets[i] > (Integer.MAX_VALUE - lastPixelOffset)) { if (dataOffsets[i] > (Integer.MAX_VALUE - lastPixelOffset)) {
throw new RasterFormatException("Incorrect band offset: " throw new RasterFormatException("Incorrect band offset: "
+ dataOffsets[i]); + dataOffsets[i]);
} }
size = lastPixelOffset + dataOffsets[i]; index = lastPixelOffset + dataOffsets[i];
if (size > maxSize) { if (index > maxIndex) {
maxSize = size; maxIndex = index;
} }
} }
if (data.length < maxSize) { if (data.length <= maxIndex) {
throw new RasterFormatException("Data array too small (should be " throw new RasterFormatException("Data array too small (should be > "
+ maxSize + " )"); + maxIndex + " )");
} }
} }