jdk/src/share/classes/sun/awt/image/IntegerComponentRaster.java
changeset 18225 35a86d260c7b
parent 16868 b5e2827ecc50
child 18246 5d1d50a81438
equal deleted inserted replaced
18224:95b6fb2f35a0 18225:35a86d260c7b
   652         if (dataOffsets[0] < 0) {
   652         if (dataOffsets[0] < 0) {
   653             throw new RasterFormatException("Data offset ("+dataOffsets[0]+
   653             throw new RasterFormatException("Data offset ("+dataOffsets[0]+
   654                                             ") must be >= 0");
   654                                             ") must be >= 0");
   655         }
   655         }
   656 
   656 
   657         int maxSize = 0;
       
   658         int size;
       
   659 
       
   660         // we can be sure that width and height are greater than 0
   657         // we can be sure that width and height are greater than 0
   661         if (scanlineStride < 0 ||
   658         if (scanlineStride < 0 ||
   662             scanlineStride > (Integer.MAX_VALUE / height))
   659             scanlineStride > (Integer.MAX_VALUE / height))
   663         {
   660         {
   664             // integer overflow
   661             // integer overflow
   680             // integer overflow
   677             // integer overflow
   681             throw new RasterFormatException("Incorrect raster attributes");
   678             throw new RasterFormatException("Incorrect raster attributes");
   682         }
   679         }
   683         lastPixelOffset += lastScanOffset;
   680         lastPixelOffset += lastScanOffset;
   684 
   681 
       
   682         int index;
       
   683         int maxIndex = 0;
   685         for (int i = 0; i < numDataElements; i++) {
   684         for (int i = 0; i < numDataElements; i++) {
   686             if (dataOffsets[i] > (Integer.MAX_VALUE - lastPixelOffset)) {
   685             if (dataOffsets[i] > (Integer.MAX_VALUE - lastPixelOffset)) {
   687                 throw new RasterFormatException("Incorrect band offset: "
   686                 throw new RasterFormatException("Incorrect band offset: "
   688                             + dataOffsets[i]);
   687                             + dataOffsets[i]);
   689             }
   688             }
   690 
   689 
   691             size = lastPixelOffset + dataOffsets[i];
   690             index = lastPixelOffset + dataOffsets[i];
   692 
   691 
   693             if (size > maxSize) {
   692             if (index > maxIndex) {
   694                 maxSize = size;
   693                 maxIndex = index;
   695             }
   694             }
   696         }
   695         }
   697         if (data.length < maxSize) {
   696         if (data.length <= maxIndex) {
   698             throw new RasterFormatException("Data array too small (should be "
   697             throw new RasterFormatException("Data array too small (should be > "
   699                     + maxSize + " )");
   698                     + maxIndex + " )");
   700         }
   699         }
   701     }
   700     }
   702 
   701 
   703     public String toString() {
   702     public String toString() {
   704         return new String ("IntegerComponentRaster: width = "+width
   703         return new String ("IntegerComponentRaster: width = "+width