pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1868217 - in /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator: DrawObject.java graphics/DrawObject.java markedcontent/DrawObject.java
Date Thu, 10 Oct 2019 06:31:35 GMT
Author: tilman
Date: Thu Oct 10 06:31:35 2019
New Revision: 1868217

URL: http://svn.apache.org/viewvc?rev=1868217&view=rev
Log:
PDFBOX-4666: avoid stackoverflow

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/DrawObject.java
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/DrawObject.java
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/DrawObject.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/DrawObject.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/DrawObject.java?rev=1868217&r1=1868216&r2=1868217&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/DrawObject.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/DrawObject.java
Thu Oct 10 06:31:35 2019
@@ -16,14 +16,17 @@
  */
 package org.apache.pdfbox.contentstream.operator;
 
+import java.io.IOException;
+import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.graphics.PDXObject;
 import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
 import org.apache.pdfbox.pdmodel.graphics.form.PDTransparencyGroup;
-
-import java.io.IOException;
-import java.util.List;
+import org.apache.pdfbox.pdmodel.PDResources;
 
 /**
  * Do: Draws an XObject.
@@ -33,6 +36,8 @@ import java.util.List;
  */
 public class DrawObject extends OperatorProcessor
 {
+    private static final Log LOG = LogFactory.getLog(DrawObject.class);
+
     @Override
     public void process(Operator operator, List<COSBase> arguments) throws IOException
     {
@@ -55,14 +60,24 @@ public class DrawObject extends Operator
         
         PDXObject xobject = context.getResources().getXObject(name);
 
-        if (xobject instanceof PDTransparencyGroup)
-        {
-            context.showTransparencyGroup((PDTransparencyGroup) xobject);
-        }
-        else if (xobject instanceof PDFormXObject)
+        if (xobject instanceof PDFormXObject)
         {
             PDFormXObject form = (PDFormXObject) xobject;
-            context.showForm(form);
+            PDResources formResources = form.getResources();
+            if (formResources != null &&
+                context.getResources().getCOSObject() == formResources.getCOSObject())
+            {
+                LOG.error("avoiding recursion with XObject '" + name.getName() + "'");
+                return;
+            }
+            if (form instanceof PDTransparencyGroup)
+            {
+                context.showTransparencyGroup((PDTransparencyGroup) form);
+            }
+            else
+            {
+                context.showForm(form);
+            }
         }
     }
 

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/DrawObject.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/DrawObject.java?rev=1868217&r1=1868216&r2=1868217&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/DrawObject.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/DrawObject.java
Thu Oct 10 06:31:35 2019
@@ -18,8 +18,10 @@ package org.apache.pdfbox.contentstream.
 
 import java.io.IOException;
 import java.util.List;
-import org.apache.pdfbox.contentstream.operator.MissingOperandException;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.contentstream.operator.MissingOperandException;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.MissingResourceException;
@@ -29,6 +31,7 @@ import org.apache.pdfbox.pdmodel.graphic
 import org.apache.pdfbox.pdmodel.graphics.PDXObject;
 import org.apache.pdfbox.contentstream.operator.Operator;
 import org.apache.pdfbox.contentstream.operator.OperatorName;
+import org.apache.pdfbox.pdmodel.PDResources;
 
 /**
  * Do: Draws an XObject.
@@ -38,6 +41,8 @@ import org.apache.pdfbox.contentstream.o
  */
 public final class DrawObject extends GraphicsOperatorProcessor
 {
+    private static final Log LOG = LogFactory.getLog(DrawObject.class);
+
     @Override
     public void process(Operator operator, List<COSBase> operands) throws IOException
     {
@@ -62,13 +67,25 @@ public final class DrawObject extends Gr
             PDImageXObject image = (PDImageXObject)xobject;
             context.drawImage(image);
         }
-        else if (xobject instanceof PDTransparencyGroup)
-        {
-            getContext().showTransparencyGroup((PDTransparencyGroup) xobject);
-        }
         else if (xobject instanceof PDFormXObject)
         {
-            getContext().showForm((PDFormXObject) xobject);
+            PDFormXObject form = (PDFormXObject) xobject;
+            PDResources formResources = form.getResources();
+            if (formResources != null &&
+                context.getResources().getCOSObject() == formResources.getCOSObject())
+            {
+                LOG.error("avoiding recursion with XObject '" + objectName.getName() + "'");
+                return;
+            }
+
+            if (form instanceof PDTransparencyGroup)
+            {
+                context.showTransparencyGroup((PDTransparencyGroup) form);
+            }
+            else
+            {
+                context.showForm(form);
+            }
         }
     }
 

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/DrawObject.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/DrawObject.java?rev=1868217&r1=1868216&r2=1868217&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/DrawObject.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/markedcontent/DrawObject.java
Thu Oct 10 06:31:35 2019
@@ -16,19 +16,22 @@
  */
 package org.apache.pdfbox.contentstream.operator.markedcontent;
 
-import org.apache.pdfbox.cos.COSBase;
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.pdmodel.graphics.PDXObject;
-import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
-import org.apache.pdfbox.pdmodel.graphics.form.PDTransparencyGroup;
-import org.apache.pdfbox.text.PDFMarkedContentExtractor;
-
 import java.io.IOException;
 import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.contentstream.operator.MissingOperandException;
 import org.apache.pdfbox.contentstream.operator.Operator;
 import org.apache.pdfbox.contentstream.operator.OperatorName;
 import org.apache.pdfbox.contentstream.operator.OperatorProcessor;
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.PDResources;
+import org.apache.pdfbox.pdmodel.graphics.PDXObject;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
+import org.apache.pdfbox.pdmodel.graphics.form.PDTransparencyGroup;
+import org.apache.pdfbox.text.PDFMarkedContentExtractor;
 
 /**
  * Do: Draws an XObject.
@@ -38,6 +41,8 @@ import org.apache.pdfbox.contentstream.o
  */
 public class DrawObject extends OperatorProcessor
 {
+    private static final Log LOG = LogFactory.getLog(DrawObject.class);
+
     @Override
     public void process(Operator operator, List<COSBase> arguments) throws IOException
     {
@@ -51,17 +56,27 @@ public class DrawObject extends Operator
             return;
         }
         COSName name = (COSName) base0;
-        PDXObject xobject =  context.getResources().getXObject(name);
+        PDXObject xobject = context.getResources().getXObject(name);
         ((PDFMarkedContentExtractor) context).xobject(xobject);
 
-        if (xobject instanceof PDTransparencyGroup)
-        {
-            context.showTransparencyGroup((PDTransparencyGroup) xobject);
-        }
-        else if (xobject instanceof PDFormXObject)
+        if (xobject instanceof PDFormXObject)
         {
             PDFormXObject form = (PDFormXObject) xobject;
-            context.showForm(form);
+            PDResources formResources = form.getResources();
+            if (formResources != null && 
+                context.getResources().getCOSObject() == formResources.getCOSObject())
+            {
+                LOG.error("avoiding recursion with XObject '" + name.getName() + "'");
+                return;
+            }
+            if (form instanceof PDTransparencyGroup)
+            {
+                context.showTransparencyGroup((PDTransparencyGroup) form);
+            }
+            else
+            {
+                context.showForm(form);
+            }
         }
     }
 



Mime
View raw message