pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1642033 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator: ./ color/
Date Thu, 27 Nov 2014 07:01:46 GMT
Author: tilman
Date: Thu Nov 27 07:01:46 2014
New Revision: 1642033

URL: http://svn.apache.org/r1642033
Log:
PDFBOX-2505: parameter validation for the device colorspace operators; code cleanup

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/Operator.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorProcessor.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetColor.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceCMYKColor.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceGrayColor.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceRGBColor.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceCMYKColor.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceGrayColor.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceRGBColor.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/Operator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/Operator.java?rev=1642033&r1=1642032&r2=1642033&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/Operator.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/Operator.java
Thu Nov 27 07:01:46 2014
@@ -27,7 +27,7 @@ import java.util.concurrent.ConcurrentHa
  */
 public class Operator
 {
-    private String theOperator;
+    private final String theOperator;
     private byte[] imageData;
     private COSDictionary imageParameters;
 
@@ -57,7 +57,7 @@ public class Operator
      */
     public static Operator getOperator( String operator )
     {
-        Operator operation = null;
+        Operator operation;
         if( operator.equals( "ID" ) || operator.equals( "BI" ) )
         {
             //we can't cache the ID operators.
@@ -96,6 +96,7 @@ public class Operator
      *
      * @return A string rep of this class.
      */
+    @Override
     public String toString()
     {
         return "PDFOperator{" + theOperator + "}";

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorProcessor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorProcessor.java?rev=1642033&r1=1642032&r2=1642033&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorProcessor.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorProcessor.java
Thu Nov 27 07:01:46 2014
@@ -20,6 +20,8 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.contentstream.PDFStreamEngine;
 import java.util.List;
 import java.io.IOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * Processes a PDF operator.
@@ -28,6 +30,11 @@ import java.io.IOException;
  */
 public abstract class OperatorProcessor
 {
+    /**
+     * Log instance.
+     */
+    private static final Log LOG = LogFactory.getLog(OperatorProcessor.class);
+
     /** The processing context. */
     protected PDFStreamEngine context;
 
@@ -66,6 +73,25 @@ public abstract class OperatorProcessor
 
     /**
      * Returns the name of this operator, e.g. "BI".
+     * @return operator name.
      */
     public abstract String getName();
+
+    /**
+     * Check the size of the arguments and puts out a warning if the size doesn't match.
+     *
+     * @param arguments Arguments for this operator.
+     * @param expectedSize Expected arguments size.
+     * @return true if size is correct, false if not.
+     */
+    protected boolean checkArgumentSize(List<COSBase> arguments, int expectedSize)
+    {
+        if (arguments.size() != expectedSize)
+        {
+            LOG.warn("'" + getName() + "' operator must have " + expectedSize
+                    + " parameters, but has " + arguments.size());
+            return false;
+}
+        return true;
+    }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetColor.java?rev=1642033&r1=1642032&r2=1642033&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetColor.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetColor.java
Thu Nov 27 07:01:46 2014
@@ -25,6 +25,7 @@ import org.apache.pdfbox.contentstream.o
 
 import java.io.IOException;
 import java.util.List;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceColorSpace;
 
 /**
  * sc,scn,SC,SCN: Sets the color to use for stroking or non-stroking operations.
@@ -36,9 +37,15 @@ public abstract class SetColor extends O
     @Override
     public void process(Operator operator, List<COSBase> arguments) throws IOException
     {
+        PDColorSpace colorSpace = getColorSpace();
+        if (colorSpace instanceof PDDeviceColorSpace
+                && !checkArgumentSize(arguments, colorSpace.getNumberOfComponents()))
+        {
+            return;
+        }
         COSArray array = new COSArray();
         array.addAll(arguments);
-        setColor(new PDColor(array, getColorSpace()));
+        setColor(new PDColor(array, colorSpace));
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceCMYKColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceCMYKColor.java?rev=1642033&r1=1642032&r2=1642033&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceCMYKColor.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceCMYKColor.java
Thu Nov 27 07:01:46 2014
@@ -19,7 +19,6 @@ package org.apache.pdfbox.contentstream.
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK;
 import org.apache.pdfbox.contentstream.operator.Operator;
 
 import java.io.IOException;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceGrayColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceGrayColor.java?rev=1642033&r1=1642032&r2=1642033&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceGrayColor.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceGrayColor.java
Thu Nov 27 07:01:46 2014
@@ -19,7 +19,6 @@ package org.apache.pdfbox.contentstream.
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
 import org.apache.pdfbox.contentstream.operator.Operator;
 
 import java.io.IOException;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceRGBColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceRGBColor.java?rev=1642033&r1=1642032&r2=1642033&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceRGBColor.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingDeviceRGBColor.java
Thu Nov 27 07:01:46 2014
@@ -19,7 +19,6 @@ package org.apache.pdfbox.contentstream.
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
 import org.apache.pdfbox.contentstream.operator.Operator;
 
 import java.io.IOException;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceCMYKColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceCMYKColor.java?rev=1642033&r1=1642032&r2=1642033&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceCMYKColor.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceCMYKColor.java
Thu Nov 27 07:01:46 2014
@@ -19,7 +19,6 @@ package org.apache.pdfbox.contentstream.
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK;
 import org.apache.pdfbox.contentstream.operator.Operator;
 
 import java.io.IOException;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceGrayColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceGrayColor.java?rev=1642033&r1=1642032&r2=1642033&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceGrayColor.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceGrayColor.java
Thu Nov 27 07:01:46 2014
@@ -19,7 +19,6 @@ package org.apache.pdfbox.contentstream.
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
 import org.apache.pdfbox.contentstream.operator.Operator;
 
 import java.io.IOException;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceRGBColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceRGBColor.java?rev=1642033&r1=1642032&r2=1642033&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceRGBColor.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingDeviceRGBColor.java
Thu Nov 27 07:01:46 2014
@@ -19,7 +19,6 @@ package org.apache.pdfbox.contentstream.
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
 import org.apache.pdfbox.contentstream.operator.Operator;
 
 import java.io.IOException;



Mime
View raw message