pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1642338 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Date Fri, 28 Nov 2014 18:25:26 GMT
Author: lehmi
Date: Fri Nov 28 18:25:26 2014
New Revision: 1642338

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

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
  (contents, props changed)

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java?rev=1642338&r1=1642337&r2=1642338&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
Fri Nov 28 18:25:26 2014
@@ -1838,30 +1838,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

Propchange: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
------------------------------------------------------------------------------
  Merged /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java:r1642337



Mime
View raw message