Handle null token in DirectObjectFinder, handle null state in SetNamedGraphicsState(), add and test and fix #874

This commit is contained in:
BobLd
2024-08-22 21:28:45 +01:00
parent 689c127cd9
commit 5c168f9cd0
5 changed files with 38 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
namespace UglyToad.PdfPig.Tests.Integration
{
public class GithubIssuesTests
{
[Fact]
public void Issue874()
{
var doc = IntegrationHelpers.GetDocumentPath("ErcotFacts.pdf");
using (var document = PdfDocument.Open(doc, new ParsingOptions() { UseLenientParsing = true, SkipMissingFonts = true }))
{
var page1 = document.GetPage(1);
Assert.Equal(1788, page1.Letters.Count);
var page2 = document.GetPage(2);
Assert.Equal(2430, page2.Letters.Count);
}
using (var document = PdfDocument.Open(doc, new ParsingOptions() { UseLenientParsing = true, SkipMissingFonts = false }))
{
var ex = Assert.Throws<ArgumentNullException>(() => document.GetPage(1));
Assert.StartsWith("Value cannot be null.", ex.Message);
}
}
}
}

View File

@@ -6,7 +6,8 @@
private static readonly HashSet<string> _documentsToIgnore =
[
"issue_671.pdf",
"GHOSTSCRIPT-698363-0.pdf"
"GHOSTSCRIPT-698363-0.pdf",
"ErcotFacts.pdf"
];
[Theory]

View File

@@ -661,6 +661,11 @@
var state = ResourceStore.GetExtendedGraphicsStateDictionary(stateName);
if (state is null)
{
return;
}
if (state.TryGet(NameToken.Lw, PdfScanner, out NumericToken? lwToken))
{
currentGraphicsState.LineWidth = lwToken.Data;

View File

@@ -32,6 +32,11 @@
{
var temp = scanner.Get(reference.Data);
if (temp is null)
{
return false;
}
if (temp.Data is T tTemp)
{
tokenResult = tTemp;