Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix resolving compressed objects in additional cross-reference table #452

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions PdfSharpCore/Pdf.IO/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,11 +1271,26 @@ private PdfTrailer ReadXRefStream(PdfCrossReferenceTable xrefTable)
ReadSymbol(Symbol.BeginStream);
ReadStream(xrefStream);

//xrefTable.Add(new PdfReference(objectID, position));
PdfReference iref = new PdfReference(xrefStream);
iref.ObjectID = objectID;
iref.Value = xrefStream;
xrefTable.Add(iref);
// An additional cross-reference (/Prev) could have been referenced in the first cross-reference by position.
// That goes into item.Type == 1 below and adds its objectID into the xrefTable with just a position and no value.
// Then we can't just do `xrefTable.Add(iref)` because that is a no-op when the objectID is already present in the ObjectTable.
// Making sure that the iref.Value is set here correctly ensure that the mechanisms in PdfReader will work correctly:
// 1. It needs to find a PdfCrossReferenceStream in iref.Value in order to resolve compressed objects.
// 2. If we leave null in iref.Value it would do redundant parsing to resolve the value again.
if (xrefTable.ObjectTable.TryGetValue(objectID, out PdfReference iref))
{
if (iref.Value == null)
{
iref.Value = xrefStream;
}
}
else
{
iref = new PdfReference(xrefStream);
iref.ObjectID = objectID;
iref.Value = xrefStream;
xrefTable.Add(iref);
}

Debug.Assert(xrefStream.Stream != null);
//string sValue = new RawEncoding().GetString(xrefStream.Stream.UnfilteredValue,);
Expand Down
Loading