File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed
Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -1271,11 +1271,26 @@ private PdfTrailer ReadXRefStream(PdfCrossReferenceTable xrefTable)
12711271 ReadSymbol ( Symbol . BeginStream ) ;
12721272 ReadStream ( xrefStream ) ;
12731273
1274- //xrefTable.Add(new PdfReference(objectID, position));
1275- PdfReference iref = new PdfReference ( xrefStream ) ;
1276- iref . ObjectID = objectID ;
1277- iref . Value = xrefStream ;
1278- xrefTable . Add ( iref ) ;
1274+ // An additional cross-reference (/Prev) could have been referenced in the first cross-reference by position.
1275+ // That goes into item.Type == 1 below and adds its objectID into the xrefTable with just a position and no value.
1276+ // Then we can't just do `xrefTable.Add(iref)` because that is a no-op when the objectID is already present in the ObjectTable.
1277+ // Making sure that the iref.Value is set here correctly ensure that the mechanisms in PdfReader will work correctly:
1278+ // 1. It needs to find a PdfCrossReferenceStream in iref.Value in order to resolve compressed objects.
1279+ // 2. If we leave null in iref.Value it would do redundant parsing to resolve the value again.
1280+ if ( xrefTable . ObjectTable . TryGetValue ( objectID , out PdfReference iref ) )
1281+ {
1282+ if ( iref . Value == null )
1283+ {
1284+ iref . Value = xrefStream ;
1285+ }
1286+ }
1287+ else
1288+ {
1289+ iref = new PdfReference ( xrefStream ) ;
1290+ iref . ObjectID = objectID ;
1291+ iref . Value = xrefStream ;
1292+ xrefTable . Add ( iref ) ;
1293+ }
12791294
12801295 Debug . Assert ( xrefStream . Stream != null ) ;
12811296 //string sValue = new RawEncoding().GetString(xrefStream.Stream.UnfilteredValue,);
You can’t perform that action at this time.
0 commit comments