#2098: scanning for stream length when it's incorrect
This commit is contained in:
parent
c3096d98d4
commit
4d9ee7b530
@ -141,6 +141,12 @@ var ChunkedStream = (function ChunkedStreamClosure() {
|
|||||||
return bytes.subarray(pos, end);
|
return bytes.subarray(pos, end);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
peekBytes: function ChunkedStream_peekBytes(length) {
|
||||||
|
var bytes = this.getBytes(length);
|
||||||
|
this.pos -= bytes.length;
|
||||||
|
return bytes;
|
||||||
|
},
|
||||||
|
|
||||||
getByteRange: function ChunkedStream_getBytes(begin, end) {
|
getByteRange: function ChunkedStream_getBytes(begin, end) {
|
||||||
this.ensureRange(begin, end);
|
this.ensureRange(begin, end);
|
||||||
return this.bytes.subarray(begin, end);
|
return this.bytes.subarray(begin, end);
|
||||||
|
@ -209,9 +209,46 @@ var Parser = (function ParserClosure() {
|
|||||||
this.shift(); // '>>'
|
this.shift(); // '>>'
|
||||||
this.shift(); // 'stream'
|
this.shift(); // 'stream'
|
||||||
if (!isCmd(this.buf1, 'endstream')) {
|
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);
|
stream = stream.makeSubStream(pos, length, dict);
|
||||||
if (cipherTransform)
|
if (cipherTransform)
|
||||||
|
@ -57,6 +57,11 @@ var Stream = (function StreamClosure() {
|
|||||||
this.pos = end;
|
this.pos = end;
|
||||||
return bytes.subarray(pos, end);
|
return bytes.subarray(pos, end);
|
||||||
},
|
},
|
||||||
|
peekBytes: function Stream_peekBytes(length) {
|
||||||
|
var bytes = this.getBytes(length);
|
||||||
|
this.pos -= bytes.length;
|
||||||
|
return bytes;
|
||||||
|
},
|
||||||
lookChar: function Stream_lookChar() {
|
lookChar: function Stream_lookChar() {
|
||||||
if (this.pos >= this.end)
|
if (this.pos >= this.end)
|
||||||
return null;
|
return null;
|
||||||
@ -161,6 +166,11 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||||||
this.pos = end;
|
this.pos = end;
|
||||||
return this.buffer.subarray(pos, end);
|
return this.buffer.subarray(pos, end);
|
||||||
},
|
},
|
||||||
|
peekBytes: function DecodeStream_peekBytes(length) {
|
||||||
|
var bytes = this.getBytes(length);
|
||||||
|
this.pos -= bytes.length;
|
||||||
|
return bytes;
|
||||||
|
},
|
||||||
lookChar: function DecodeStream_lookChar() {
|
lookChar: function DecodeStream_lookChar() {
|
||||||
var pos = this.pos;
|
var pos = this.pos;
|
||||||
while (this.bufferLength <= pos) {
|
while (this.bufferLength <= pos) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user