mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-06-28 15:30:17 +08:00
Support finding object declarations without endobj on previous object
This commit is contained in:
parent
bd9702a402
commit
1bfd6dedb4
@ -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);
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user