diff --git a/src/UglyToad.PdfPig.Tests/Integration/Documents/ErcotFacts.pdf b/src/UglyToad.PdfPig.Tests/Integration/Documents/ErcotFacts.pdf new file mode 100644 index 00000000..bdeb0c7d Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Integration/Documents/ErcotFacts.pdf differ diff --git a/src/UglyToad.PdfPig.Tests/Integration/GithubIssuesTests.cs b/src/UglyToad.PdfPig.Tests/Integration/GithubIssuesTests.cs new file mode 100644 index 00000000..9d4a5bc4 --- /dev/null +++ b/src/UglyToad.PdfPig.Tests/Integration/GithubIssuesTests.cs @@ -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(() => document.GetPage(1)); + Assert.StartsWith("Value cannot be null.", ex.Message); + } + } + } +} diff --git a/src/UglyToad.PdfPig.Tests/Integration/IntegrationDocumentTests.cs b/src/UglyToad.PdfPig.Tests/Integration/IntegrationDocumentTests.cs index 8b628fc6..7ffa391b 100644 --- a/src/UglyToad.PdfPig.Tests/Integration/IntegrationDocumentTests.cs +++ b/src/UglyToad.PdfPig.Tests/Integration/IntegrationDocumentTests.cs @@ -6,7 +6,8 @@ private static readonly HashSet _documentsToIgnore = [ "issue_671.pdf", - "GHOSTSCRIPT-698363-0.pdf" + "GHOSTSCRIPT-698363-0.pdf", + "ErcotFacts.pdf" ]; [Theory] diff --git a/src/UglyToad.PdfPig/Graphics/BaseStreamProcessor.cs b/src/UglyToad.PdfPig/Graphics/BaseStreamProcessor.cs index 7159008d..a3467f68 100644 --- a/src/UglyToad.PdfPig/Graphics/BaseStreamProcessor.cs +++ b/src/UglyToad.PdfPig/Graphics/BaseStreamProcessor.cs @@ -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; diff --git a/src/UglyToad.PdfPig/Parser/Parts/DirectObjectFinder.cs b/src/UglyToad.PdfPig/Parser/Parts/DirectObjectFinder.cs index b88b08c2..0a84a81b 100644 --- a/src/UglyToad.PdfPig/Parser/Parts/DirectObjectFinder.cs +++ b/src/UglyToad.PdfPig/Parser/Parts/DirectObjectFinder.cs @@ -32,6 +32,11 @@ { var temp = scanner.Get(reference.Data); + if (temp is null) + { + return false; + } + if (temp.Data is T tTemp) { tokenResult = tTemp;