Skip to content

Commit

Permalink
PDFBOX-5283: irgnore wrong object number in lenient mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Schmidor committed Sep 24, 2021
1 parent 4896c6f commit 8604732
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1235,19 +1235,22 @@ private COSObjectKey findObjectKey(COSObjectKey objectKey, long offset) throws I
{
source.seek(offset);
// try to read the given object/generation number
if (objectKey.getNumber() == readObjectNumber())
long foundObjectNumber = readObjectNumber();
if(objectKey.getNumber() != foundObjectNumber){
LOG.warn("found wrong object number. expected [" + objectKey.getNumber() +"] found ["+ foundObjectNumber + "]");
if(!isLenient) return null;
}

int genNumber = readGenerationNumber();
// finally try to read the object marker
readExpectedString(OBJ_MARKER, true);
if (genNumber == objectKey.getGeneration())
{
int genNumber = readGenerationNumber();
// finally try to read the object marker
readExpectedString(OBJ_MARKER, true);
if (genNumber == objectKey.getGeneration())
{
return objectKey;
}
else if (isLenient && genNumber > objectKey.getGeneration())
{
return new COSObjectKey(objectKey.getNumber(), genNumber);
}
return objectKey;
}
else if (isLenient && genNumber > objectKey.getGeneration())
{
return new COSObjectKey(objectKey.getNumber(), genNumber);
}
}
catch (IOException exception)
Expand Down Expand Up @@ -1322,7 +1325,7 @@ private Map<COSObjectKey, Long> bfSearchForObjects() throws IOException
// add the former object ID only if there was a subsequent object ID
bfCOSObjectKeyOffsets.put(
new COSObjectKey(lastObjectId, lastGenID), lastObjOffset);
}
}
lastObjectId = objectId;
lastGenID = genID;
lastObjOffset = tempOffset + 1;
Expand Down

0 comments on commit 8604732

Please sign in to comment.