pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1795705 - in /pdfbox/trunk: ./ pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
Date Sun, 21 May 2017 14:26:07 GMT
Author: lehmi
Date: Sun May 21 14:26:06 2017
New Revision: 1795705

URL: http://svn.apache.org/viewvc?rev=1795705&view=rev
Log:
PDFBOX-3798: don't add cut off objects when performing a brute force search

Modified:
    pdfbox/trunk/   (props changed)
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java   (contents,
props changed)

Propchange: pdfbox/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun May 21 14:26:06 2017
@@ -1,3 +1,3 @@
-/pdfbox/branches/2.0:1760418,1761484,1762133,1763609,1779822,1780783,1780789,1782684,1784450,1792784
+/pdfbox/branches/2.0:1760418,1761484,1762133,1763609,1779822,1780783,1780789,1782684,1784450,1792784,1795704
 /pdfbox/branches/no-awt:1618517-1621410
 /pdfbox/no-awt:1618514-1618516

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=1795705&r1=1795704&r2=1795705&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 May 21
14:26:06 2017
@@ -1421,6 +1421,9 @@ public class COSParser extends BaseParse
             bfSearchCOSObjectKeyOffsets = new HashMap<>();
             long originOffset = source.getPosition();
             long currentOffset = MINIMUM_SEARCH_OFFSET;
+            long lastObjectId = Long.MIN_VALUE;
+            int lastGenID = Integer.MIN_VALUE;
+            long lastObjOffset = Long.MIN_VALUE;
             String objString = " obj";
             char[] string = objString.toCharArray();
             do
@@ -1452,9 +1455,17 @@ public class COSParser extends BaseParse
                             if (objectIDFound)
                             {
                                 source.read();
-                                long objectID = readObjectNumber();
-                                bfSearchCOSObjectKeyOffsets.put(new COSObjectKey(objectID,
genID),
-                                        tempOffset + 1);
+                                long objectId = readObjectNumber();
+                                if (lastObjOffset > 0)
+                                {
+                                    // add the former object ID only if there was a subsequent
object ID
+                                    bfSearchCOSObjectKeyOffsets
+                                            .put(new COSObjectKey(lastObjectId, lastGenID),
+                                                    lastObjOffset);
+                                }
+                                lastObjectId = objectId;
+                                lastGenID = genID;
+                                lastObjOffset = tempOffset + 1;
                             }
                         }
                     }
@@ -1462,6 +1473,13 @@ public class COSParser extends BaseParse
                 currentOffset++;
             }
             while (currentOffset < lastEOFMarker && !source.isEOF());
+            if (lastEOFMarker < Long.MAX_VALUE && lastObjOffset > 0)
+            {
+                // if the pdf wasn't cut off in the middle the last object id has to added
here
+                // so that it can't get lost as there isn't any subsequent object id
+                bfSearchCOSObjectKeyOffsets.put(new COSObjectKey(lastObjectId, lastGenID),
+                        lastObjOffset);
+            }
             // reestablish origin position
             source.seek(originOffset);
         }

Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun May 21 14:26:06 2017
@@ -1,4 +1,4 @@
 /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java:1641458
-/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java:1779822,1780783,1792784,1792839
+/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java:1779822,1780783,1792784,1792839,1795704
 /pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java:1618517-1621410
 /pdfbox/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java:1618514-1618516



Mime
View raw message