diff --git a/src/core/obj.js b/src/core/obj.js index 10f61c90a..93bcde59f 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -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; } diff --git a/src/core/stream.js b/src/core/stream.js index c225bfe8b..20717d3dc 100644 --- a/src/core/stream.js +++ b/src/core/stream.js @@ -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); }, diff --git a/test/pdfs/issue13130.pdf.link b/test/pdfs/issue13130.pdf.link new file mode 100644 index 000000000..17b9439ca --- /dev/null +++ b/test/pdfs/issue13130.pdf.link @@ -0,0 +1 @@ +https://web.archive.org/web/20210328094625/https://akmer.aikucun.com/a94a8fe5ccb19ba61c4c0873d391e987982fbbd3_1616477914120_83.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index fd9a72678..42746e39d 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -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",