Skip to content
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
14 changes: 14 additions & 0 deletions src/UglyToad.PdfPig.Tests/Integration/GithubIssuesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@

public class GithubIssuesTests
{
[Fact]
public void Issues1332_1()
{
var path = IntegrationHelpers.GetSpecificTestDocumentPath("0012156.pdf");
using (var document = PdfDocument.Open(path, new ParsingOptions() { UseLenientParsing = true }))
{
foreach (var page in document.GetPages())
{
Assert.NotNull(page);
Assert.NotEmpty(page.Paths);
}
}
}

[Fact]
public void Issues1332()
{
Expand Down
Binary file not shown.
11 changes: 11 additions & 0 deletions src/UglyToad.PdfPig.Tokenization/Scanner/CoreTokenScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ public void Seek(long position)
inputBytes.Seek(position);
}

/// <summary>
/// Discards any byte that was read ahead of the current token (see <see cref="ITokenizer.ReadsNextByte"/>).
/// This must be called after seeking to an absolute position where the next <see cref="MoveNext"/> is
/// expected to read the byte at that position, otherwise the stale pre-read byte from the previous
/// location is reused and tokenization starts one byte too late.
/// </summary>
public void ClearPreReadByte()
{
hasBytePreRead = false;
}

/// <inheritdoc />
public bool MoveNext()
{
Expand Down
6 changes: 5 additions & 1 deletion src/UglyToad.PdfPig/Tokenization/Scanner/PdfTokenScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,8 @@ public void DeregisterCustomTokenizer(ITokenizer tokenizer)

Seek(offset.Value1);

coreTokenScanner.ClearPreReadByte();

if (!MoveNext())
{
TryBruteForceFileToFindReference(reference, out var bfObjectToken);
Expand Down Expand Up @@ -817,9 +819,11 @@ private bool TryBruteForceFileToFindReference(IndirectReference reference, [NotN
{
// Brute force read the entire file
isBruteForcing = true;

Seek(fileHeaderOffset.Value);

coreTokenScanner.ClearPreReadByte();

while (MoveNext())
{
objectLocationProvider.Cache((ObjectToken)CurrentToken!, true);
Expand Down
Loading