Support finding object declarations without endobj on previous object

This commit is contained in:
Arnaud TAMAILLON 2024-09-01 13:11:46 +02:00 committed by BobLd
parent bd9702a402
commit 1bfd6dedb4
2 changed files with 60 additions and 0 deletions

View File

@ -233,6 +233,41 @@ endobj";
Assert.Equal(TestDataOffsets, locations.Values);
}
[Fact]
public void BruteForceSearcherFindsAllObjectsWhenMissingEndObj()
{
const string s = @"%PDF-1.7
abcd
1 0 obj
<< /Type /Any >>
2 0 obj
<< /Type /Any >>
%AZ 0 obj
11 0 obj
769
endobj
%%EOF";
var bytes = new MemoryInputBytes(OtherEncodings.StringAsLatin1Bytes(s));
var locations = BruteForceSearcher.GetObjectLocations(bytes);
Assert.Equal(3, locations.Count);
var expectedLocations = new long[]
{
s.IndexOf("1 0 obj", StringComparison.OrdinalIgnoreCase),
s.IndexOf("2 0 obj", StringComparison.OrdinalIgnoreCase),
s.IndexOf("11 0 obj", StringComparison.OrdinalIgnoreCase)
};
Assert.Equal(expectedLocations, locations.Values);
}
private static string GetStringAt(IInputBytes bytes, long location)
{
bytes.Seek(location);

View File

@ -82,6 +82,31 @@
currentOffset++;
}
}
else if (ReadHelper.IsWhitespace(bytes.CurrentByte))
{
var next = bytes.Peek();
if (next.HasValue && next.Value == 'o')
{
if (ReadHelper.IsString(bytes, " obj"))
{
currentlyInObject = false;
currentOffset--;
loopProtection = 0;
}
else
{
bytes.MoveNext();
currentOffset++;
loopProtection = 0;
}
}
else
{
bytes.MoveNext();
currentOffset++;
loopProtection = 0;
}
}
else
{
bytes.MoveNext();