mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-08-20 09:37:44 +08:00
Add Stream with Invalid Length unit test
This commit is contained in:
parent
e5076a605e
commit
4153e4a1b4
@ -256,6 +256,44 @@ A¡¬àð‰É©ˆ°‘¼›‚%¥×s³®í»š}%§X{{tøNåÝž¶ö¢ÖÞ¾
|
||||
Assert.Equal(2, locationProvider.Offsets[new IndirectReference(352, 0)]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadsStreamObjectWithInvalidLength()
|
||||
{
|
||||
string invalidLengthStream = "ABCD" + new string('e', 3996);
|
||||
|
||||
string s = $@"
|
||||
352 0 obj
|
||||
<< /S 1273 /Filter /FlateDecode /Length 353 0 R >>
|
||||
stream
|
||||
{invalidLengthStream}
|
||||
endstream
|
||||
endobj
|
||||
353 0 obj
|
||||
1479
|
||||
endobj";
|
||||
|
||||
var locationProvider = new TestObjectLocationProvider();
|
||||
// Mark location of "353 0 obj"
|
||||
locationProvider.Offsets[new IndirectReference(353, 0)] = 1643;
|
||||
|
||||
var scanner = GetScanner(s, locationProvider);
|
||||
|
||||
var tokens = ReadToEnd(scanner);
|
||||
|
||||
Assert.Equal(2, tokens.Count);
|
||||
|
||||
var stream = Assert.IsType<StreamToken>(tokens[0].Data);
|
||||
|
||||
var data = stream.Data.ToArray();
|
||||
|
||||
var str = Encoding.UTF8.GetString(data);
|
||||
|
||||
Assert.Equal(data.Length, invalidLengthStream.Length);
|
||||
Assert.StartsWith("ABCDeeeee", str);
|
||||
|
||||
Assert.Equal(2, locationProvider.Offsets[new IndirectReference(352, 0)]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadsSimpleStreamObject()
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user