Skip to content

Commit

Permalink
Support parsing lines after references count in lenient mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud TAMAILLON authored and BobLd committed Sep 2, 2024
1 parent cf45dcf commit f4d1456
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,35 @@ 0000000250 00032 n
Assert.Equal(2, result.ObjectOffsets.Count);
}

[Fact]
public void ParseEntriesAfterDeclaredCountIfLenient()
{
const string data = @"xref
0 5
0000000003 65535 f
0000000090 00000 n
0000000081 00000 n
0000000223 00000 n
0000000331 00000 n
0000000127 00000 n
0000000409 00000 f
0000000418 00000 n
trailer
<< >>";
// Strict parsing
var input = StringBytesTestConverter.Scanner(data);
var act = () => CrossReferenceTableParser.Parse(input.scanner, 0, false);
var ex = Assert.Throws<PdfDocumentFormatException>(act);
Assert.Equal("Found a line with 2 unexpected entries in the cross reference table: 127, 0.", ex.Message);

// Lenient Parsing
input = StringBytesTestConverter.Scanner(data);
var result = CrossReferenceTableParser.Parse(input.scanner, 0, true);

Assert.Equal(6, result.ObjectOffsets.Count);
}

private static CoreTokenScanner GetReader(string input)
{
return StringBytesTestConverter.Scanner(input).scanner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ static string GetErrorMessage(ReadOnlySpan<IToken> tokens)
}
}

throw new PdfDocumentFormatException($"Found a line with 2 unexpected entries in the cross reference table: {tokens[0]}, {tokens[1]}.");
if (!isLenientParsing)
{
throw new PdfDocumentFormatException($"Found a line with 2 unexpected entries in the cross reference table: {tokens[0]}, {tokens[1]}.");
}

}

if (tokens.Length <= 2)
Expand Down

0 comments on commit f4d1456

Please sign in to comment.