pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1557395 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/GRestore.java
Date Sat, 11 Jan 2014 13:45:19 GMT
Author: lehmi
Date: Sat Jan 11 13:45:18 2014
New Revision: 1557395

URL: http://svn.apache.org/r1557395
Log:
PDFBOX-161: avoid EmptyStackException if the number of q/Q-operators isn't well balanced

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/GRestore.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/GRestore.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/GRestore.java?rev=1557395&r1=1557394&r2=1557395&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/GRestore.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/operator/GRestore.java
Sat Jan 11 13:45:18 2014
@@ -18,24 +18,40 @@ package org.apache.pdfbox.util.operator;
 
 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.pdmodel.graphics.PDGraphicsState;
 import org.apache.pdfbox.util.PDFOperator;
 
 /**
- *
+ * Process the Q operator.
+ * 
  * @author Huault : huault@free.fr
- * @version $Revision: 1.4 $
+ * 
  */
 public class GRestore extends OperatorProcessor
 {
+	
     /**
-     * process : Q : Restore graphics state.
-     * @param operator The operator that is being executed.
-     * @param arguments List
+     * Log instance.
+     */
+    private static final Log LOG = LogFactory.getLog(GRestore.class);
+
+    /**
+     * {@inheritDoc}
      */
     public void process(PDFOperator operator, List<COSBase> arguments)
     {
-        context.setGraphicsState( (PDGraphicsState)context.getGraphicsStack().pop() );
+    	if (context.getGraphicsStack().size() > 0)
+    	{
+    		context.setGraphicsState( (PDGraphicsState)context.getGraphicsStack().pop() );
+    	}
+    	else
+    	{
+    		// this shouldn't happen but it does, see PDFBOX-161
+    		// TODO make this self healing mechanism optional for preflight??
+    		LOG.debug("GRestore: no graphics state left to be restored.");
+    	}
     }
 }



Mime
View raw message