pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1809501 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
Date Sun, 24 Sep 2017 11:10:57 GMT
Author: lehmi
Date: Sun Sep 24 11:10:56 2017
New Revision: 1809501

URL: http://svn.apache.org/viewvc?rev=1809501&view=rev
Log:
PDFBOX-3934: removed brute force search for last startxref entry fall back to rebuildTrailer
instead, improved garbage detection

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java?rev=1809501&r1=1809500&r2=1809501&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java Sun Sep 24
11:10:56 2017
@@ -441,34 +441,14 @@ public class COSParser extends BaseParse
         }
         // find last startxref preceding EOF marker
         bufOff = lastIndexOf(STARTXREF, buf, bufOff);
-        long startXRefOffset = skipBytes + bufOff;
-
         if (bufOff < 0)
         {
-            if (isLenient) 
-            {
-                LOG.debug("Performing brute force search for last startxref entry");
-                long bfOffset = bfSearchForLastStartxrefEntry();
-                boolean offsetIsValid = false;
-                if (bfOffset > -1)
-                {
-                    source.seek(bfOffset);
-                    long bfXref = parseStartXref();
-                    if (bfXref > -1)
-                    {
-                        offsetIsValid = checkXRefOffset(bfXref) == bfXref;
-                    }
-                }
-                source.seek(0);
-                // use the new offset only if it is a valid pointer to a xref table
-                return offsetIsValid ? bfOffset : -1;
-            }
-            else
-            {
-                throw new IOException("Missing 'startxref' marker.");
-            }
+            throw new IOException("Missing 'startxref' marker.");
+        }
+        else
+        {
+            return skipBytes + bufOff;
         }
-        return startXRefOffset;
     }
     
     /**
@@ -1667,8 +1647,11 @@ public class COSParser extends BaseParse
                         // which most likely indicates that the pdf is linearized,
                         // updated or just cut off somewhere in the middle
                         skipSpaces();
-                        readObjectNumber();
-                        readGenerationNumber();
+                        if (!isString(XREF_TABLE))
+                        {
+                            readObjectNumber();
+                            readGenerationNumber();
+                        }
                     }
                     catch (IOException exception)
                     {
@@ -1721,28 +1704,6 @@ public class COSParser extends BaseParse
     }
 
     /**
-     * Brute force search for the last startxref entry.
-     * 
-     * @throws IOException if something went wrong
-     */
-    private long bfSearchForLastStartxrefEntry() throws IOException
-    {
-        long lastStartxref = -1;
-        source.seek(MINIMUM_SEARCH_OFFSET);
-        // search for startxref
-        while (!source.isEOF())
-        {
-            if (isString(STARTXREF))
-            {
-                lastStartxref = source.getPosition();
-                source.seek(lastStartxref + 9);
-            }
-            source.read();
-        }
-        return lastStartxref;
-    }
-
-    /**
      * Brute force search for all /XRef entries (streams).
      * 
      * @throws IOException if something went wrong



Mime
View raw message