Skip to content

Commit f4e7db5

Browse files
committed
Simply order by offset also when not doing brute force to fix #1208
1 parent 52ecef0 commit f4e7db5

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

src/UglyToad.PdfPig.Tests/Integration/GithubIssuesTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,29 @@
66
using PdfPig.Core;
77
using PdfPig.Tokens;
88
using SkiaSharp;
9+
using UglyToad.PdfPig.AcroForms;
10+
using UglyToad.PdfPig.AcroForms.Fields;
911

1012
public class GithubIssuesTests
1113
{
14+
[Fact]
15+
public void Issue1208()
16+
{
17+
string[] files = ["Input.visible.pdf", "Input.invisible.pdf"];
18+
19+
foreach (var file in files)
20+
{
21+
var path = IntegrationHelpers.GetSpecificTestDocumentPath(file);
22+
23+
using (var document = PdfDocument.Open(path, new ParsingOptions() { UseLenientParsing = true }))
24+
{
25+
Assert.True(document.TryGetForm(out AcroForm form));
26+
Assert.Single(form.Fields);
27+
Assert.Equal(AcroFieldType.Signature, form.Fields[0].FieldType);
28+
}
29+
}
30+
}
31+
1232
[Fact]
1333
public void Revert_e11dc6b()
1434
{
Binary file not shown.
Binary file not shown.

src/UglyToad.PdfPig/Parser/FileStructure/FirstPassParser.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public static FirstPassResults Parse(
6161
}
6262
else
6363
{
64+
/* Code below commented to fix issue #1208, while not failing test Issue874
65+
* The logic would need to be reviewed before re-enabling.
66+
6467
// If we didn't brute force then use the previous position for ordering.
6568
foreach (var obj in streamsAndTables)
6669
{
@@ -81,6 +84,11 @@ public static FirstPassResults Parse(
8184
orderedXrefs.Add(obj);
8285
}
8386
}
87+
*/
88+
89+
orderedXrefs.AddRange(
90+
streamsAndTables
91+
.OrderBy(x => x.Offset));
8492
}
8593

8694
DictionaryToken? lastTrailer = null;

0 commit comments

Comments
 (0)