You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2014/11/28 19:23:44 UTC

svn commit: r1642337 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java

Author: lehmi
Date: Fri Nov 28 18:23:44 2014
New Revision: 1642337

URL: http://svn.apache.org/r1642337
Log:
PDFBOX-2521: improved self repair mechanism to avoid false positives

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=1642337&r1=1642336&r2=1642337&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 Nov 28 18:23:44 2014
@@ -1910,30 +1910,36 @@ public class NonSequentialPDFParser exte
         {
             return startXRefOffset;
         }
-        setPdfSource(startXRefOffset);
+        setPdfSource(startXRefOffset-1);
+        // save th previous character
+        int previous = pdfSource.read();
         if (pdfSource.peek() == X && checkBytesAtOffset(XREF_TABLE))
         {
             return startXRefOffset;
         }
-        int nextValue = pdfSource.peek();
-        // maybe there isn't a xref table but a xref stream
-        // is the next character a digit?
-        if (nextValue > 47 && nextValue < 57)
+        // the previous character has to be a whitespace
+        if (isWhitespace(previous))
         {
-            try
+            int nextValue = pdfSource.peek();
+            // maybe there isn't a xref table but a xref stream
+            // is the next character a digit?
+            if (nextValue > 47 && nextValue < 57)
             {
-                // Maybe it's a XRef stream
-                readObjectNumber();
-                readGenerationNumber();
-                readPattern(OBJ_MARKER);
-                setPdfSource(startXRefOffset);
-                return startXRefOffset;
-            }
-            catch (IOException exception)
-            {
-                // there wasn't an object of a xref stream
-                // try to repair the offset
-                pdfSource.seek(startXRefOffset);
+                try
+                {
+                    // Maybe it's a XRef stream
+                    readObjectNumber();
+                    readGenerationNumber();
+                    readPattern(OBJ_MARKER);
+                    setPdfSource(startXRefOffset);
+                    return startXRefOffset;
+                }
+                catch (IOException exception)
+                {
+                    // there wasn't an object of a xref stream
+                    // try to repair the offset
+                    pdfSource.seek(startXRefOffset);
+                }
             }
         }
         // try to find a fixed offset