Skip extra objects in object stream in using offsets
This commit is contained in:
parent
81c602c61c
commit
9296ee6986
@ -2151,12 +2151,13 @@ var XRef = (function XRefClosure() {
|
|||||||
"invalid first and n parameters for ObjStm stream"
|
"invalid first and n parameters for ObjStm stream"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const parser = new Parser({
|
let parser = new Parser({
|
||||||
lexer: new Lexer(stream),
|
lexer: new Lexer(stream),
|
||||||
xref: this,
|
xref: this,
|
||||||
allowStreams: true,
|
allowStreams: true,
|
||||||
});
|
});
|
||||||
const nums = new Array(n);
|
const nums = new Array(n);
|
||||||
|
const offsets = new Array(n);
|
||||||
// read the object numbers to populate cache
|
// read the object numbers to populate cache
|
||||||
for (let i = 0; i < n; ++i) {
|
for (let i = 0; i < n; ++i) {
|
||||||
const num = parser.getObj();
|
const num = parser.getObj();
|
||||||
@ -2172,17 +2173,27 @@ var XRef = (function XRefClosure() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
nums[i] = num;
|
nums[i] = num;
|
||||||
|
offsets[i] = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const start = (stream.start || 0) + first;
|
||||||
const entries = new Array(n);
|
const entries = new Array(n);
|
||||||
// read stream objects for cache
|
// read stream objects for cache
|
||||||
for (let i = 0; i < n; ++i) {
|
for (let i = 0; i < n; ++i) {
|
||||||
|
const length = i < n - 1 ? offsets[i + 1] - offsets[i] : undefined;
|
||||||
|
if (length < 0) {
|
||||||
|
throw new FormatError("Invalid offset in the ObjStm stream.");
|
||||||
|
}
|
||||||
|
parser = new Parser({
|
||||||
|
lexer: new Lexer(
|
||||||
|
stream.makeSubStream(start + offsets[i], length, stream.dict)
|
||||||
|
),
|
||||||
|
xref: this,
|
||||||
|
allowStreams: true,
|
||||||
|
});
|
||||||
|
|
||||||
const obj = parser.getObj();
|
const obj = parser.getObj();
|
||||||
entries[i] = obj;
|
entries[i] = obj;
|
||||||
// The ObjStm should not contain 'endobj'. If it's present, skip over it
|
|
||||||
// to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
|
|
||||||
if (parser.buf1 instanceof Cmd && parser.buf1.cmd === "endobj") {
|
|
||||||
parser.shift();
|
|
||||||
}
|
|
||||||
if (isStream(obj)) {
|
if (isStream(obj)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -259,9 +259,15 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||||||
return bytes;
|
return bytes;
|
||||||
},
|
},
|
||||||
makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
|
makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
|
||||||
var end = start + length;
|
if (length === undefined) {
|
||||||
while (this.bufferLength <= end && !this.eof) {
|
while (!this.eof) {
|
||||||
this.readBlock();
|
this.readBlock();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var end = start + length;
|
||||||
|
while (this.bufferLength <= end && !this.eof) {
|
||||||
|
this.readBlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return new Stream(this.buffer, start, length, dict);
|
return new Stream(this.buffer, start, length, dict);
|
||||||
},
|
},
|
||||||
|
1
test/pdfs/issue13130.pdf.link
Normal file
1
test/pdfs/issue13130.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://web.archive.org/web/20210328094625/https://akmer.aikucun.com/a94a8fe5ccb19ba61c4c0873d391e987982fbbd3_1616477914120_83.pdf
|
@ -18,6 +18,15 @@
|
|||||||
"type": "eq",
|
"type": "eq",
|
||||||
"renderTaskOnContinue": true
|
"renderTaskOnContinue": true
|
||||||
},
|
},
|
||||||
|
{ "id": "issue13130",
|
||||||
|
"file": "pdfs/issue13130.pdf",
|
||||||
|
"md5": "318518299132fe3b52252ca43a69a23e",
|
||||||
|
"rounds": 1,
|
||||||
|
"link": true,
|
||||||
|
"firstPage": 2,
|
||||||
|
"lastPage": 2,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{ "id": "tracemonkey-fbf",
|
{ "id": "tracemonkey-fbf",
|
||||||
"file": "pdfs/tracemonkey.pdf",
|
"file": "pdfs/tracemonkey.pdf",
|
||||||
"md5": "9a192d8b1a7dc652a19835f6f08098bd",
|
"md5": "9a192d8b1a7dc652a19835f6f08098bd",
|
||||||
@ -2037,7 +2046,7 @@
|
|||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"link": true,
|
"link": true,
|
||||||
"lastPage": 1,
|
"lastPage": 1,
|
||||||
"type": "load",
|
"type": "eq",
|
||||||
"about": "ObjStm stream containing 'endobj' commands."
|
"about": "ObjStm stream containing 'endobj' commands."
|
||||||
},
|
},
|
||||||
{ "id": "ocs",
|
{ "id": "ocs",
|
||||||
|
Loading…
Reference in New Issue
Block a user