mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
#2098: scanning for stream length when it's incorrect
This commit is contained in:
parent
c3096d98d4
commit
4d9ee7b530
3 changed files with 55 additions and 2 deletions
|
@ -209,9 +209,46 @@ var Parser = (function ParserClosure() {
|
|||
this.shift(); // '>>'
|
||||
this.shift(); // 'stream'
|
||||
if (!isCmd(this.buf1, 'endstream')) {
|
||||
warn('Missing endstream');
|
||||
// bad stream length, scanning for endstream
|
||||
stream.pos = pos;
|
||||
var SCAN_BLOCK_SIZE = 2048;
|
||||
var ENDSTREAM_SIGNATURE_LENGTH = 9;
|
||||
var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
|
||||
0x61, 0x6D];
|
||||
var skipped = 0, found = false;
|
||||
while (stream.pos < stream.end) {
|
||||
var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
|
||||
var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
|
||||
var found = false, i, ii, j;
|
||||
for (i = 0, j = 0; i < scanLength; i++) {
|
||||
var b = scanBytes[i];
|
||||
if (b !== ENDSTREAM_SIGNATURE[j]) {
|
||||
i -= j;
|
||||
j = 0;
|
||||
} else {
|
||||
j++;
|
||||
if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
|
||||
stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
|
||||
break;
|
||||
}
|
||||
skipped += scanLength;
|
||||
stream.pos += scanLength;
|
||||
}
|
||||
if (!found) {
|
||||
error('Missing endstream');
|
||||
}
|
||||
length = skipped;
|
||||
this.shift();
|
||||
this.shift();
|
||||
}
|
||||
this.shift();
|
||||
this.shift(); // 'endstream'
|
||||
|
||||
stream = stream.makeSubStream(pos, length, dict);
|
||||
if (cipherTransform)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue