pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1855638 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java
Date Sat, 16 Mar 2019 12:46:42 GMT
Author: tilman
Date: Sat Mar 16 12:46:42 2019
New Revision: 1855638

URL: http://svn.apache.org/viewvc?rev=1855638&view=rev
Log:
PDFBOX-4488: wrap NegativeArraySizeException into IOException

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java?rev=1855638&r1=1855637&r2=1855638&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java
Sat Mar 16 12:46:42 2019
@@ -205,26 +205,32 @@ final class SampledImageReader
             throw new IOException("image width and height must be positive");
         }
 
-        if (bitsPerComponent == 1 && colorKey == null && numComponents ==
1)
+        try
         {
-            return from1Bit(pdImage, clipped, subsampling, width, height);
-        }
+            if (bitsPerComponent == 1 && colorKey == null && numComponents
== 1)
+            {
+                return from1Bit(pdImage, clipped, subsampling, width, height);
+            }
 
-        //
-        // An AWT raster must use 8/16/32 bits per component. Images with < 8bpc
-        // will be unpacked into a byte-backed raster. Images with 16bpc will be reduced
-        // in depth to 8bpc as they will be drawn to TYPE_INT_RGB images anyway. All code
-        // in PDColorSpace#toRGBImage expects an 8-bit range, i.e. 0-255.
-        // Interleaved raster allows chunk-copying for 8-bit images.
-        WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width,
height,
-                numComponents, new Point(0, 0));
-        final float[] defaultDecode = pdImage.getColorSpace().getDefaultDecode(8);
-        if (bitsPerComponent == 8 && Arrays.equals(decode, defaultDecode) &&
colorKey == null)
+            // An AWT raster must use 8/16/32 bits per component. Images with < 8bpc
+            // will be unpacked into a byte-backed raster. Images with 16bpc will be reduced
+            // in depth to 8bpc as they will be drawn to TYPE_INT_RGB images anyway. All
code
+            // in PDColorSpace#toRGBImage expects an 8-bit range, i.e. 0-255.
+            // Interleaved raster allows chunk-copying for 8-bit images.
+            WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
width, height,
+                    numComponents, new Point(0, 0));
+            final float[] defaultDecode = pdImage.getColorSpace().getDefaultDecode(8);
+            if (bitsPerComponent == 8 && Arrays.equals(decode, defaultDecode) &&
colorKey == null)
+            {
+                // convert image, faster path for non-decoded, non-colormasked 8-bit images
+                return from8bit(pdImage, raster, clipped, subsampling, width, height);
+            }
+            return fromAny(pdImage, raster, colorKey, clipped, subsampling, width, height);
+        }
+        catch (NegativeArraySizeException ex)
         {
-            // convert image, faster path for non-decoded, non-colormasked 8-bit images
-            return from8bit(pdImage, raster, clipped, subsampling, width, height);
+            throw new IOException(ex);
         }
-        return fromAny(pdImage, raster, colorKey, clipped, subsampling, width, height);
     }
 
     private static BufferedImage from1Bit(PDImage pdImage, Rectangle clipped, final int subsampling,



Mime
View raw message