Skip to content
Merged
Show file tree
Hide file tree
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
Binary file not shown.
27 changes: 27 additions & 0 deletions src/UglyToad.PdfPig.Tests/Integration/GithubIssuesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,33 @@ public void Issue1208()
}
}

[Fact]
public void Issue1209()
{
var path = IntegrationHelpers.GetDocumentPath("MOZILLA-9176-2.pdf");

using (var document = PdfDocument.Open(path, new ParsingOptions() { UseLenientParsing = true }))
{
for (int p = 1; p <= document.NumberOfPages; p++)
{
var page = document.GetPage(p);
Assert.NotNull(page);

foreach (var image in page.GetImages())
{
Assert.True(image.ImageDictionary.ContainsKey(NameToken.Height)); // Was missing
Assert.True(image.ImageDictionary.ContainsKey(NameToken.Width));

if (image.ImageDictionary.TryGet<DictionaryToken>(NameToken.DecodeParms, out var decodeParms))
{
Assert.True(decodeParms.ContainsKey(NameToken.Columns)); // Was missing
Assert.True(decodeParms.ContainsKey(NameToken.Rows));
}
}
}
}
}

[Fact]
public void Revert_e11dc6b()
{
Expand Down
18 changes: 18 additions & 0 deletions src/UglyToad.PdfPig/PdfExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Core;
using Filters;
using Parser.Parts;
Expand Down Expand Up @@ -156,6 +157,23 @@ private static double GetEstimatedSizeMultiplier(IFilter filter)
resolvedItems[NameToken.Create(kvp.Key)] = ResolveInternal(value, scanner, visited);
}

if (resolvedItems.Count != dict.Data.Count)
{
if (resolvedItems.Count > dict.Data.Count)
{
throw new InvalidOperationException("Resolved more items than were present in the original dictionary. This should not be possible.");
}

// We missed some due to cycles, try and resolve them now.
foreach (var missing in dict.Data.Keys.Except(resolvedItems.Keys.Select(k => k.Data), StringComparer.OrdinalIgnoreCase))
{
if (dict.Data[missing] is IndirectReferenceToken reference)
{
resolvedItems[NameToken.Create(missing)] = ResolveInternal(reference, scanner, visited);
}
}
}

return new DictionaryToken(resolvedItems);
}

Expand Down
Loading