Merge pull request #13152 from calixteman/13130
Skip extra objects in object stream in using offsets
This commit is contained in:
commit
1a2cdaffc5
@ -2151,12 +2151,13 @@ var XRef = (function XRefClosure() {
|
||||
"invalid first and n parameters for ObjStm stream"
|
||||
);
|
||||
}
|
||||
const parser = new Parser({
|
||||
let parser = new Parser({
|
||||
lexer: new Lexer(stream),
|
||||
xref: this,
|
||||
allowStreams: true,
|
||||
});
|
||||
const nums = new Array(n);
|
||||
const offsets = new Array(n);
|
||||
// read the object numbers to populate cache
|
||||
for (let i = 0; i < n; ++i) {
|
||||
const num = parser.getObj();
|
||||
@ -2172,17 +2173,27 @@ var XRef = (function XRefClosure() {
|
||||
);
|
||||
}
|
||||
nums[i] = num;
|
||||
offsets[i] = offset;
|
||||
}
|
||||
|
||||
const start = (stream.start || 0) + first;
|
||||
const entries = new Array(n);
|
||||
// read stream objects for cache
|
||||
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();
|
||||
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)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -259,9 +259,15 @@ var DecodeStream = (function DecodeStreamClosure() {
|
||||
return bytes;
|
||||
},
|
||||
makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
|
||||
var end = start + length;
|
||||
while (this.bufferLength <= end && !this.eof) {
|
||||
this.readBlock();
|
||||
if (length === undefined) {
|
||||
while (!this.eof) {
|
||||
this.readBlock();
|
||||
}
|
||||
} else {
|
||||
var end = start + length;
|
||||
while (this.bufferLength <= end && !this.eof) {
|
||||
this.readBlock();
|
||||
}
|
||||
}
|
||||
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",
|
||||
"renderTaskOnContinue": true
|
||||
},
|
||||
{ "id": "issue13130",
|
||||
"file": "pdfs/issue13130.pdf",
|
||||
"md5": "318518299132fe3b52252ca43a69a23e",
|
||||
"rounds": 1,
|
||||
"link": true,
|
||||
"firstPage": 2,
|
||||
"lastPage": 2,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "tracemonkey-fbf",
|
||||
"file": "pdfs/tracemonkey.pdf",
|
||||
"md5": "9a192d8b1a7dc652a19835f6f08098bd",
|
||||
@ -2037,7 +2046,7 @@
|
||||
"rounds": 1,
|
||||
"link": true,
|
||||
"lastPage": 1,
|
||||
"type": "load",
|
||||
"type": "eq",
|
||||
"about": "ObjStm stream containing 'endobj' commands."
|
||||
},
|
||||
{ "id": "ocs",
|
||||
|
Loading…
Reference in New Issue
Block a user