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:
parent
81172b571f
commit
cb55506b95
@ -147,10 +147,9 @@ var Parser = (function ParserClosure() {
|
||||
* Find the end of the stream by searching for the /EI\s/.
|
||||
* @returns {number} The inline stream length.
|
||||
*/
|
||||
findDefaultInlineStreamEnd:
|
||||
function Parser_findDefaultInlineStreamEnd(stream) {
|
||||
var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
|
||||
var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
|
||||
findDefaultInlineStreamEnd(stream) {
|
||||
const E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD, n = 5;
|
||||
let startPos = stream.pos, state = 0, ch, maybeEIPos;
|
||||
while ((ch = stream.getByte()) !== -1) {
|
||||
if (state === 0) {
|
||||
state = (ch === E) ? 1 : 0;
|
||||
@ -159,10 +158,10 @@ var Parser = (function ParserClosure() {
|
||||
} else {
|
||||
assert(state === 2);
|
||||
if (ch === SPACE || ch === LF || ch === CR) {
|
||||
// Let's check the next five bytes are ASCII... just be sure.
|
||||
n = 5;
|
||||
followingBytes = stream.peekBytes(n);
|
||||
for (i = 0; i < n; i++) {
|
||||
maybeEIPos = stream.pos;
|
||||
// Let's check the next `n` bytes are ASCII... just be sure.
|
||||
let followingBytes = stream.peekBytes(n);
|
||||
for (let i = 0; i < n; i++) {
|
||||
ch = followingBytes[i];
|
||||
if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
|
||||
// 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);
|
||||
},
|
||||
/**
|
||||
|
1
test/pdfs/issue8798.pdf.link
Normal file
1
test/pdfs/issue8798.pdf.link
Normal file
@ -0,0 +1 @@
|
||||
https://github.com/mozilla/pdf.js/files/1241137/output_34.pdf
|
@ -2966,6 +2966,14 @@
|
||||
"type": "eq",
|
||||
"about": "Inline image with ASCII85Decode filter."
|
||||
},
|
||||
{ "id": "issue8798",
|
||||
"file": "pdfs/issue8798.pdf",
|
||||
"md5": "e9e60ea3f8f33850b0333fb04e074e64",
|
||||
"rounds": 1,
|
||||
"lastPage": 1,
|
||||
"link": true,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "issue8613",
|
||||
"file": "pdfs/issue8613.pdf",
|
||||
"md5": "bc7ad2db75710aa9916c5769e0c02123",
|
||||
|
Loading…
Reference in New Issue
Block a user