Support parsing lines after references count in lenient mode

This commit is contained in:
Arnaud TAMAILLON
2024-09-02 21:22:56 +01:00
committed by BobLd
parent cf45dcf6ad
commit f4d1456489
2 changed files with 34 additions and 1 deletions
@@ -283,6 +283,35 @@ trailer
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;
@@ -126,7 +126,11 @@
}
}
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)