pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1615141 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Date Fri, 01 Aug 2014 15:29:09 GMT
Author: lehmi
Date: Fri Aug  1 15:29:09 2014
New Revision: 1615141

URL: http://svn.apache.org/r1615141
Log:
PDFBOX-2250: detect XRef streams to avoid false positives when searching for the XRef table/stream

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java?rev=1615141&r1=1615140&r2=1615141&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Fri Aug  1 15:29:09 2014
@@ -1713,14 +1713,37 @@ public class NonSequentialPDFParser exte
      */
     private long calculateFixingOffset(long startXRefOffset) throws IOException
     {
-    	// TODO check offset for XRef stream objects
     	setPdfSource(startXRefOffset);
     	if (pdfSource.peek() == X && calculateFixingOffset(startXRefOffset, XREF) ==
0)
     	{
     		return 0;
     	}
-    	long fixingOffset = calculateFixingOffset(startXRefOffset, XREF);
-   		return fixingOffset;
+        int nextValue = pdfSource.peek();
+        // is the next character a digit?
+        if (nextValue > 47 && nextValue < 57)
+        {
+            // save the origin offset
+            long originOffset = pdfSource.getOffset();
+            try
+            {
+                // Maybe it's a XRef stream
+                readObjectNumber();
+                readGenerationNumber();
+                readPattern(OBJ_MARKER);
+                setPdfSource(startXRefOffset);
+                return 0;
+            }
+            catch (IOException exception)
+            {
+                setPdfSource(startXRefOffset);
+            }
+            finally
+            {
+                pdfSource.seek(originOffset);
+            }
+        }
+        // TODO try to repair for XRef streams
+        return  calculateFixingOffset(startXRefOffset, XREF);
     }
 
     /**



Mime
View raw message