Author: lehmi
Date: Sat Mar 10 13:42:15 2018
New Revision: 1826403

URL: http://svn.apache.org/viewvc?rev=1826403&view=rev
Log:
PDFBOX-4084: be lenient if the read generation number is bigger than the 
expected one

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

Modified: 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java?rev=1826403&r1=1826402&r2=1826403&view=diff
==============================================================================
--- 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
 (original)
+++ 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
 Sat Mar 10 13:42:15 2018
@@ -1395,7 +1395,7 @@ public class COSParser extends BaseParse
         {
             COSObjectKey objectKey = objectEntry.getKey();
             Long objectOffset = objectEntry.getValue();
-            // a negative offset number represents a object number itself
+            // a negative offset number represents an object number itself
             // see type 2 entry in xref stream
             if (objectOffset != null && objectOffset >= 0
                     && !checkObjectKey(objectKey, objectOffset))
@@ -1449,27 +1449,27 @@ public class COSParser extends BaseParse
             return false;
         }
         boolean objectKeyFound = false;
-        long originOffset = source.getPosition();
         try 
         {
             source.seek(offset);
             // try to read the given object/generation number
-            if (objectKey.getNumber() == readObjectNumber()
-                    && objectKey.getGeneration() == readGenerationNumber())
+            if (objectKey.getNumber() == readObjectNumber())
             {
-                // finally tro to read the object marker
-                readExpectedString(OBJ_MARKER, true);
-                objectKeyFound = true;
+                int genNumber = readGenerationNumber();
+                //
+                if (genNumber == objectKey.getGeneration()
+                        || (isLenient && genNumber > 
objectKey.getGeneration()))
+                {
+                    // finally try to read the object marker
+                    readExpectedString(OBJ_MARKER, true);
+                    objectKeyFound = true;
+                }
             }
         }
         catch (IOException exception)
         {
             // Swallow the exception, obviously there isn't any valid object 
number
         }
-        finally 
-        {
-            source.seek(originOffset);
-        }
         // return resulting value
         return objectKeyFound;
     }


Reply via email to