pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1605545 - in /pdfbox/trunk: fontbox/src/main/java/org/apache/fontbox/cff/Type1CharString.java pdfbox/src/main/java/org/apache/pdfbox/cos/COSNull.java pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java
Date Wed, 25 Jun 2014 18:44:02 GMT
Author: tilman
Date: Wed Jun 25 18:44:01 2014
New Revision: 1605545

URL: http://svn.apache.org/r1605545
Log:
PDFBOX-2158: be lenient / avoid NPE with bad decode arrays; be lenient towards fonts with
lineTo without moveTo

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type1CharString.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSNull.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type1CharString.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type1CharString.java?rev=1605545&r1=1605544&r2=1605545&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type1CharString.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/Type1CharString.java Wed Jun
25 18:44:01 2014
@@ -333,7 +333,15 @@ public class Type1CharString
     {
         float x = (float)current.getX() + dx.floatValue();
         float y = (float)current.getY() + dy.floatValue();
-        path.lineTo(x, y);
+        if (path.getCurrentPoint() == null)
+        {
+            LOG.warn("rlineTo without initial moveTo in font " + fontName + ", glyph " +
glyphName);
+            path.moveTo(x, y);
+        }
+        else
+        {
+            path.lineTo(x, y);
+        }
         current.setLocation(x, y);
     }
 
@@ -349,7 +357,15 @@ public class Type1CharString
         float y2 = y1 + dy2.floatValue();
         float x3 = x2 + dx3.floatValue();
         float y3 = y2 + dy3.floatValue();
-        path.curveTo(x1, y1, x2, y2, x3, y3);
+        if (path.getCurrentPoint() == null)
+        {
+            LOG.warn("rrcurveTo without initial moveTo in font " + fontName + ", glyph "
+ glyphName);
+            path.moveTo(x3, y3);
+        }
+        else
+        {
+            path.curveTo(x1, y1, x2, y2, x3, y3);
+        }
         current.setLocation(x3, y3);
     }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSNull.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSNull.java?rev=1605545&r1=1605544&r2=1605545&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSNull.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSNull.java Wed Jun 25 18:44:01
2014
@@ -52,6 +52,7 @@ public class COSNull extends COSBase
      * @return any object, depending on the visitor implementation, or null
      * @throws IOException If an error occurs while visiting this object.
      */
+    @Override
     public Object accept( ICOSVisitor  visitor ) throws IOException
     {
         return visitor.visitFromNull( this );
@@ -67,4 +68,13 @@ public class COSNull extends COSBase
     {
         output.write(NULL_BYTES);
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString()
+    {
+        return "COSNull{}";
+    }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java?rev=1605545&r1=1605544&r2=1605545&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/SampledImageReader.java
Wed Jun 25 18:44:01 2014
@@ -37,6 +37,8 @@ import org.apache.pdfbox.pdmodel.graphic
 
 import javax.imageio.stream.ImageInputStream;
 import javax.imageio.stream.MemoryCacheImageInputStream;
+import org.apache.pdfbox.cos.COSFloat;
+import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.pdmodel.common.PDMemoryStream;
 
 /**
@@ -420,24 +422,31 @@ final class SampledImageReader
 
         if (cosDecode != null)
         {
-            decode = cosDecode.toFloatArray();
-
-            // if ImageMask is true then decode must be [0 1] or [1 0]
-            if (pdImage.isStencil() && (decode.length != 2 ||
-                decode[0] < 0 || decode[0] > 1 ||
-                decode[1] < 0 || decode[1] > 1))
+            int numberOfComponents = pdImage.getColorSpace().getNumberOfComponents();
+            if (cosDecode.size() != numberOfComponents * 2)
             {
-                LOG.warn("Ignored invalid decode array: not compatible with ImageMask");
-                decode = null;
+                if (pdImage.isStencil() && cosDecode.size() >= 2
+                        && cosDecode.get(0) instanceof COSNumber
+                        && cosDecode.get(1) instanceof COSNumber)
+                {
+                    float decode0 = ((COSFloat) cosDecode.get(0)).floatValue();
+                    float decode1 = ((COSFloat) cosDecode.get(1)).floatValue();
+                    if (decode0 >= 0 && decode0 <= 1 && decode1 >=
0 && decode1 <= 1)
+                    {
+                        LOG.warn("decode array " + cosDecode
+                                + " not compatible with color space, using the first two
entries");
+                        return new float[]
+                        {
+                            decode0, decode1
+                        };
+                    }
+                }
+                LOG.error("decode array " + cosDecode
+                        + " not compatible with color space, using default");
             }
-
-            // otherwise, its length shall be twice the number of colour
-            // components required by ColorSpace
-            int n = pdImage.getColorSpace().getNumberOfComponents();
-            if (decode != null && decode.length != n * 2)
+            else
             {
-                LOG.warn("Ignored invalid decode array: not compatible with color space");
-                decode = null;
+                decode = cosDecode.toFloatArray();
             }
         }
 



Mime
View raw message