Skip to content

Commit

Permalink
Handle null token in DirectObjectFinder, handle null state in SetName…
Browse files Browse the repository at this point in the history
…dGraphicsState(), add and test and fix #874
  • Loading branch information
BobLd committed Sep 29, 2024
1 parent 689c127 commit 5c168f9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
Binary file not shown.
26 changes: 26 additions & 0 deletions src/UglyToad.PdfPig.Tests/Integration/GithubIssuesTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ public class IntegrationDocumentTests
private static readonly HashSet<string> _documentsToIgnore =
[
"issue_671.pdf",
"GHOSTSCRIPT-698363-0.pdf"
"GHOSTSCRIPT-698363-0.pdf",
"ErcotFacts.pdf"
];

[Theory]
Expand Down
5 changes: 5 additions & 0 deletions src/UglyToad.PdfPig/Graphics/BaseStreamProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,11 @@ public virtual void SetNamedGraphicsState(NameToken stateName)

var state = ResourceStore.GetExtendedGraphicsStateDictionary(stateName);

if (state is null)
{
return;
}

if (state.TryGet(NameToken.Lw, PdfScanner, out NumericToken? lwToken))
{
currentGraphicsState.LineWidth = lwToken.Data;
Expand Down
5 changes: 5 additions & 0 deletions src/UglyToad.PdfPig/Parser/Parts/DirectObjectFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public static bool TryGet<T>(IToken? token, IPdfTokenScanner scanner, [NotNullWh
{
var temp = scanner.Get(reference.Data);

if (temp is null)
{
return false;
}

if (temp.Data is T tTemp)
{
tokenResult = tTemp;
Expand Down

0 comments on commit 5c168f9

Please sign in to comment.