From 751e9707e72a9c803ded6b179e458501c87e2038 Mon Sep 17 00:00:00 2001 From: Oliver Schmidtmer Date: Thu, 23 Sep 2021 23:31:03 +0200 Subject: [PATCH] PDFBOX-5283: ignore dublicate object keys when correcting xRefs --- .../main/java/org/apache/pdfbox/pdfparser/COSParser.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java index 31b9a341bc6..fa3f9414dac 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java @@ -1320,8 +1320,13 @@ private Map bfSearchForObjects() throws IOException if (lastObjOffset > 0) { // add the former object ID only if there was a subsequent object ID - bfCOSObjectKeyOffsets.put( - new COSObjectKey(lastObjectId, lastGenID), lastObjOffset); + COSObjectKey objectKey = new COSObjectKey(lastObjectId, lastGenID); + if(!bfCOSObjectKeyOffsets.containsKey(objectKey)) { + bfCOSObjectKeyOffsets.put(objectKey, lastObjOffset); + } else { + LOG.debug("Ignoring duplicate object key (" + objectKey + + ")"); + } } lastObjectId = objectId; lastGenID = genID;