@@ -1159,6 +1159,7 @@ private boolean validateXrefOffsets(Map<COSObjectKey, Long> xrefOffset) throws I
1159
1159
return true ;
1160
1160
}
1161
1161
Map <COSObjectKey , COSObjectKey > correctedKeys = new HashMap <>();
1162
+ Map <COSObjectKey , COSObjectKey > validKeys = new HashMap <>();
1162
1163
for (Entry <COSObjectKey , Long > objectEntry : xrefOffset .entrySet ())
1163
1164
{
1164
1165
COSObjectKey objectKey = objectEntry .getKey ();
@@ -1178,13 +1179,18 @@ else if (foundObjectKey != objectKey)
1178
1179
{
1179
1180
// Generation was fixed - need to update map later, after iteration
1180
1181
correctedKeys .put (objectKey , foundObjectKey );
1182
+ } else {
1183
+ validKeys .put (objectKey , foundObjectKey );
1181
1184
}
1182
1185
}
1183
1186
}
1184
1187
for (Entry <COSObjectKey , COSObjectKey > correctedKeyEntry : correctedKeys .entrySet ())
1185
1188
{
1186
- xrefOffset .put (correctedKeyEntry .getValue (),
1187
- xrefOffset .remove (correctedKeyEntry .getKey ()));
1189
+ if (!validKeys .containsKey (correctedKeyEntry .getValue ())) {
1190
+ // Only replacy entries, if the original entry does not point to a valid object
1191
+ xrefOffset .put (correctedKeyEntry .getValue (),
1192
+ xrefOffset .remove (correctedKeyEntry .getKey ()));
1193
+ }
1188
1194
}
1189
1195
return true ;
1190
1196
}
@@ -1237,8 +1243,10 @@ private COSObjectKey findObjectKey(COSObjectKey objectKey, long offset) throws I
1237
1243
// try to read the given object/generation number
1238
1244
long foundObjectNumber = readObjectNumber ();
1239
1245
if (objectKey .getNumber () != foundObjectNumber ){
1246
+ System .out .println ("found wrong object number. expected [" + objectKey .getNumber () +"] found [" + foundObjectNumber + "]" );
1240
1247
LOG .warn ("found wrong object number. expected [" + objectKey .getNumber () +"] found [" + foundObjectNumber + "]" );
1241
1248
if (!isLenient ) return null ;
1249
+ else objectKey = new COSObjectKey (foundObjectNumber , objectKey .getGeneration ());
1242
1250
}
1243
1251
1244
1252
int genNumber = readGenerationNumber ();
0 commit comments