Merge pull request #7021 from Snuffleupagus/bug-1250079
Add a `recoveryMode` that suppresses errors from the `Parser`, and utilize it when searching for the main trailer in `XRef_indexObjects` (bug 1250079)
This commit is contained in:
commit
084fc517fe
@ -970,13 +970,15 @@ var XRef = (function XRefClosure() {
|
|||||||
var dict;
|
var dict;
|
||||||
for (i = 0, ii = trailers.length; i < ii; ++i) {
|
for (i = 0, ii = trailers.length; i < ii; ++i) {
|
||||||
stream.pos = trailers[i];
|
stream.pos = trailers[i];
|
||||||
var parser = new Parser(new Lexer(stream), true, this);
|
var parser = new Parser(new Lexer(stream), /* allowStreams = */ true,
|
||||||
|
/* xref = */ this, /* recoveryMode = */ true);
|
||||||
var obj = parser.getObj();
|
var obj = parser.getObj();
|
||||||
if (!isCmd(obj, 'trailer')) {
|
if (!isCmd(obj, 'trailer')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// read the trailer dictionary
|
// read the trailer dictionary
|
||||||
if (!isDict(dict = parser.getObj())) {
|
dict = parser.getObj();
|
||||||
|
if (!isDict(dict)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// taking the first one with 'ID'
|
// taking the first one with 'ID'
|
||||||
|
@ -66,10 +66,11 @@ function isEOF(v) {
|
|||||||
var MAX_LENGTH_TO_CACHE = 1000;
|
var MAX_LENGTH_TO_CACHE = 1000;
|
||||||
|
|
||||||
var Parser = (function ParserClosure() {
|
var Parser = (function ParserClosure() {
|
||||||
function Parser(lexer, allowStreams, xref) {
|
function Parser(lexer, allowStreams, xref, recoveryMode) {
|
||||||
this.lexer = lexer;
|
this.lexer = lexer;
|
||||||
this.allowStreams = allowStreams;
|
this.allowStreams = allowStreams;
|
||||||
this.xref = xref;
|
this.xref = xref;
|
||||||
|
this.recoveryMode = recoveryMode || false;
|
||||||
this.imageCache = Object.create(null);
|
this.imageCache = Object.create(null);
|
||||||
this.refill();
|
this.refill();
|
||||||
}
|
}
|
||||||
@ -115,8 +116,11 @@ var Parser = (function ParserClosure() {
|
|||||||
array.push(this.getObj(cipherTransform));
|
array.push(this.getObj(cipherTransform));
|
||||||
}
|
}
|
||||||
if (isEOF(this.buf1)) {
|
if (isEOF(this.buf1)) {
|
||||||
|
if (!this.recoveryMode) {
|
||||||
error('End of file inside array');
|
error('End of file inside array');
|
||||||
}
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
this.shift();
|
this.shift();
|
||||||
return array;
|
return array;
|
||||||
case '<<': // dictionary or stream
|
case '<<': // dictionary or stream
|
||||||
@ -136,8 +140,11 @@ var Parser = (function ParserClosure() {
|
|||||||
dict.set(key, this.getObj(cipherTransform));
|
dict.set(key, this.getObj(cipherTransform));
|
||||||
}
|
}
|
||||||
if (isEOF(this.buf1)) {
|
if (isEOF(this.buf1)) {
|
||||||
|
if (!this.recoveryMode) {
|
||||||
error('End of file inside dictionary');
|
error('End of file inside dictionary');
|
||||||
}
|
}
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
|
||||||
// Stream objects are not allowed inside content streams or
|
// Stream objects are not allowed inside content streams or
|
||||||
// object streams.
|
// object streams.
|
||||||
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -99,6 +99,7 @@
|
|||||||
!bug911034.pdf
|
!bug911034.pdf
|
||||||
!bug1108301.pdf
|
!bug1108301.pdf
|
||||||
!bug1157493.pdf
|
!bug1157493.pdf
|
||||||
|
!bug1250079.pdf
|
||||||
!pdfjsbad1586.pdf
|
!pdfjsbad1586.pdf
|
||||||
!freeculture.pdf
|
!freeculture.pdf
|
||||||
!issue6006.pdf
|
!issue6006.pdf
|
||||||
|
BIN
test/pdfs/bug1250079.pdf
Normal file
BIN
test/pdfs/bug1250079.pdf
Normal file
Binary file not shown.
@ -730,6 +730,13 @@
|
|||||||
"link": false,
|
"link": false,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{ "id": "bug1250079",
|
||||||
|
"file": "pdfs/bug1250079.pdf",
|
||||||
|
"md5": "a1dd21a70ae7097d96273e85a80b26ef",
|
||||||
|
"rounds": 1,
|
||||||
|
"link": false,
|
||||||
|
"type": "load"
|
||||||
|
},
|
||||||
{ "id": "hudsonsurvey",
|
{ "id": "hudsonsurvey",
|
||||||
"file": "pdfs/hudsonsurvey.pdf",
|
"file": "pdfs/hudsonsurvey.pdf",
|
||||||
"md5": "bf0e6576a7b6c2fe7485bce1b78e006f",
|
"md5": "bf0e6576a7b6c2fe7485bce1b78e006f",
|
||||||
|
Loading…
Reference in New Issue
Block a user