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
@@ -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,);

Unchanged files with check annotations Beta

{
return ResolveFontConfig().Where(x => x.EndsWith(".ttf", StringComparison.OrdinalIgnoreCase)).ToArray();
}
catch(Exception ex)

Check warning on line 137 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (3.1.x)

The variable 'ex' is declared but never used

Check warning on line 137 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (3.1.x)

The variable 'ex' is declared but never used

Check warning on line 137 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (5.0.x)

The variable 'ex' is declared but never used

Check warning on line 137 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (5.0.x)

The variable 'ex' is declared but never used

Check warning on line 137 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (6.0.x)

The variable 'ex' is declared but never used

Check warning on line 137 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (6.0.x)

The variable 'ex' is declared but never used

Check warning on line 137 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (7.0.x)

The variable 'ex' is declared but never used

Check warning on line 137 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (7.0.x)

The variable 'ex' is declared but never used

Check warning on line 137 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (8.0.x)

The variable 'ex' is declared but never used

Check warning on line 137 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (8.0.x)

The variable 'ex' is declared but never used
{
#if DEBUG
Console.Error.WriteLine(ex.ToString());
} // Whend
} // End Using reader
}
catch (Exception ex)

Check warning on line 197 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (3.1.x)

The variable 'ex' is declared but never used

Check warning on line 197 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (3.1.x)

The variable 'ex' is declared but never used

Check warning on line 197 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (5.0.x)

The variable 'ex' is declared but never used

Check warning on line 197 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (5.0.x)

The variable 'ex' is declared but never used

Check warning on line 197 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (6.0.x)

The variable 'ex' is declared but never used

Check warning on line 197 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (6.0.x)

The variable 'ex' is declared but never used

Check warning on line 197 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (7.0.x)

The variable 'ex' is declared but never used

Check warning on line 197 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (7.0.x)

The variable 'ex' is declared but never used

Check warning on line 197 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (8.0.x)

The variable 'ex' is declared but never used

Check warning on line 197 in PdfSharpCore/Utils/LinuxSystemFontResolver.cs

GitHub Actions / build (8.0.x)

The variable 'ex' is declared but never used
{
#if DEBUG
Console.Error.WriteLine(ex.Message);
Debug.WriteLine(fontPathFile);
tempFontInfoList.Add(fontInfo);
}
catch (System.Exception e)

Check warning on line 126 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (3.1.x)

The variable 'e' is declared but never used

Check warning on line 126 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (3.1.x)

The variable 'e' is declared but never used

Check warning on line 126 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (5.0.x)

The variable 'e' is declared but never used

Check warning on line 126 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (5.0.x)

The variable 'e' is declared but never used

Check warning on line 126 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (6.0.x)

The variable 'e' is declared but never used

Check warning on line 126 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (6.0.x)

The variable 'e' is declared but never used

Check warning on line 126 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (7.0.x)

The variable 'e' is declared but never used

Check warning on line 126 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (7.0.x)

The variable 'e' is declared but never used

Check warning on line 126 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (8.0.x)

The variable 'e' is declared but never used

Check warning on line 126 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (8.0.x)

The variable 'e' is declared but never used
{
#if DEBUG
System.Console.Error.WriteLine(e);
FontFamilyModel family = DeserializeFontFamily(familyName, familyGroup);
InstalledFonts.Add(familyName.ToLower(), family);
}
catch (System.Exception e)

Check warning on line 142 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (3.1.x)

The variable 'e' is declared but never used

Check warning on line 142 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (3.1.x)

The variable 'e' is declared but never used

Check warning on line 142 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (5.0.x)

The variable 'e' is declared but never used

Check warning on line 142 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (5.0.x)

The variable 'e' is declared but never used

Check warning on line 142 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (6.0.x)

The variable 'e' is declared but never used

Check warning on line 142 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (6.0.x)

The variable 'e' is declared but never used

Check warning on line 142 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (7.0.x)

The variable 'e' is declared but never used

Check warning on line 142 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (7.0.x)

The variable 'e' is declared but never used

Check warning on line 142 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (8.0.x)

The variable 'e' is declared but never used

Check warning on line 142 in PdfSharpCore/Utils/FontResolver.cs

GitHub Actions / build (8.0.x)

The variable 'e' is declared but never used
{
#if DEBUG
System.Console.Error.WriteLine(e);
double _lineHeight;
// Bounding box of the formatted text after layout
private XRect _textLayout;

Check warning on line 96 in PdfSharpCore/Drawing.Layout/XTextFormatter.cs

GitHub Actions / build (3.1.x)

The field 'XTextFormatter._textLayout' is never used

Check warning on line 96 in PdfSharpCore/Drawing.Layout/XTextFormatter.cs

GitHub Actions / build (3.1.x)

The field 'XTextFormatter._textLayout' is never used

Check warning on line 96 in PdfSharpCore/Drawing.Layout/XTextFormatter.cs

GitHub Actions / build (5.0.x)

The field 'XTextFormatter._textLayout' is never used

Check warning on line 96 in PdfSharpCore/Drawing.Layout/XTextFormatter.cs

GitHub Actions / build (5.0.x)

The field 'XTextFormatter._textLayout' is never used

Check warning on line 96 in PdfSharpCore/Drawing.Layout/XTextFormatter.cs

GitHub Actions / build (6.0.x)

The field 'XTextFormatter._textLayout' is never used

Check warning on line 96 in PdfSharpCore/Drawing.Layout/XTextFormatter.cs

GitHub Actions / build (6.0.x)

The field 'XTextFormatter._textLayout' is never used

Check warning on line 96 in PdfSharpCore/Drawing.Layout/XTextFormatter.cs

GitHub Actions / build (7.0.x)

The field 'XTextFormatter._textLayout' is never used

Check warning on line 96 in PdfSharpCore/Drawing.Layout/XTextFormatter.cs

GitHub Actions / build (7.0.x)

The field 'XTextFormatter._textLayout' is never used

Check warning on line 96 in PdfSharpCore/Drawing.Layout/XTextFormatter.cs

GitHub Actions / build (8.0.x)

The field 'XTextFormatter._textLayout' is never used

Check warning on line 96 in PdfSharpCore/Drawing.Layout/XTextFormatter.cs

GitHub Actions / build (8.0.x)

The field 'XTextFormatter._textLayout' is never used
/// <summary>
/// Gets or sets the bounding box of the layout.