Try to recover if we reach the end of the stream when searching for the EI marker of an inline image (issue 8798)

This commit is contained in:
Jonas Jenwald 2017-08-21 14:34:15 +02:00
parent 81172b571f
commit cb55506b95
3 changed files with 25 additions and 8 deletions

View File

@ -147,10 +147,9 @@ var Parser = (function ParserClosure() {
* Find the end of the stream by searching for the /EI\s/. * Find the end of the stream by searching for the /EI\s/.
* @returns {number} The inline stream length. * @returns {number} The inline stream length.
*/ */
findDefaultInlineStreamEnd: findDefaultInlineStreamEnd(stream) {
function Parser_findDefaultInlineStreamEnd(stream) { const E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD, n = 5;
var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD; let startPos = stream.pos, state = 0, ch, maybeEIPos;
var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
while ((ch = stream.getByte()) !== -1) { while ((ch = stream.getByte()) !== -1) {
if (state === 0) { if (state === 0) {
state = (ch === E) ? 1 : 0; state = (ch === E) ? 1 : 0;
@ -159,10 +158,10 @@ var Parser = (function ParserClosure() {
} else { } else {
assert(state === 2); assert(state === 2);
if (ch === SPACE || ch === LF || ch === CR) { if (ch === SPACE || ch === LF || ch === CR) {
// Let's check the next five bytes are ASCII... just be sure. maybeEIPos = stream.pos;
n = 5; // Let's check the next `n` bytes are ASCII... just be sure.
followingBytes = stream.peekBytes(n); let followingBytes = stream.peekBytes(n);
for (i = 0; i < n; i++) { for (let i = 0; i < n; i++) {
ch = followingBytes[i]; ch = followingBytes[i];
if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) { if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
// Not a LF, CR, SPACE or any visible ASCII character, i.e. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
@ -179,6 +178,15 @@ var Parser = (function ParserClosure() {
} }
} }
} }
if (ch === -1) {
warn('findDefaultInlineStreamEnd: ' +
'Reached the end of the stream without finding a valid EI marker');
if (maybeEIPos) {
warn('... trying to recover by using the last "EI" occurrence.');
stream.skip(-(stream.pos - maybeEIPos)); // Reset the stream position.
}
}
return ((stream.pos - 4) - startPos); return ((stream.pos - 4) - startPos);
}, },
/** /**

View File

@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/1241137/output_34.pdf

View File

@ -2966,6 +2966,14 @@
"type": "eq", "type": "eq",
"about": "Inline image with ASCII85Decode filter." "about": "Inline image with ASCII85Decode filter."
}, },
{ "id": "issue8798",
"file": "pdfs/issue8798.pdf",
"md5": "e9e60ea3f8f33850b0333fb04e074e64",
"rounds": 1,
"lastPage": 1,
"link": true,
"type": "eq"
},
{ "id": "issue8613", { "id": "issue8613",
"file": "pdfs/issue8613.pdf", "file": "pdfs/issue8613.pdf",
"md5": "bc7ad2db75710aa9916c5769e0c02123", "md5": "bc7ad2db75710aa9916c5769e0c02123",