Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 29, 2024
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.
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 @@ -665,6 +665,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
Loading