< prev index next >
src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java
Print this page
@@ -1035,11 +1035,19 @@
int bitDepth = metadata.IHDR_bitDepth;
int inputBands = inputBandsForColorType[metadata.IHDR_colorType];
int bytesPerPixel = (bitDepth == 16) ? 2 : 1;
bytesPerPixel *= inputBands;
- int bytesPerRow = (inputBands*passWidth*bitDepth + 7)/8;
+ /*
+ * When we multiply passWidth with inputBands/bitDepth if the
+ * resultant value exceeds maximum value for int, bufferoverflow happens
+ * and the value will be invalid. So until we calculate bytesPerRow
+ * value by dividing it by 8 we can maintain bitsPerRow value in long
+ * so that final bytesPerRow value is valid.
+ */
+ long bitsPerRow = ((long)inputBands) * passWidth * bitDepth;
+ int bytesPerRow = (int)((bitsPerRow + 7)/8);
int eltsPerRow = (bitDepth == 16) ? bytesPerRow/2 : bytesPerRow;
// If no pixels need updating, just skip the input data
if (updateWidth == 0) {
for (int srcY = 0; srcY < passHeight; srcY++) {
< prev index next >