mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-11-18 17:17:54 +08:00
Ensure no key end up missing in ResolveInternal and fix #1209
This commit is contained in:
Binary file not shown.
@@ -29,6 +29,33 @@
|
||||
}
|
||||
}
|
||||
|
||||
[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()
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Core;
|
||||
using Filters;
|
||||
using Parser.Parts;
|
||||
@@ -156,6 +157,23 @@
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user