Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop caching Streams in XRef.fetchCompressed #11370

Merged
merged 2 commits into from
Nov 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions src/core/obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -1707,13 +1707,13 @@ var XRef = (function XRefClosure() {
},

fetchCompressed(ref, xrefEntry, suppressEncryption = false) {
var tableOffset = xrefEntry.offset;
var stream = this.fetch(Ref.get(tableOffset, 0));
const tableOffset = xrefEntry.offset;
const stream = this.fetch(Ref.get(tableOffset, 0));
if (!isStream(stream)) {
throw new FormatError('bad ObjStm stream');
}
var first = stream.dict.get('First');
var n = stream.dict.get('N');
const first = stream.dict.get('First');
const n = stream.dict.get('N');
if (!Number.isInteger(first) || !Number.isInteger(n)) {
throw new FormatError(
'invalid first and n parameters for ObjStm stream');
Expand All @@ -1723,33 +1723,37 @@ var XRef = (function XRefClosure() {
xref: this,
allowStreams: true,
});
var i, entries = [], num, nums = [];
const nums = new Array(n);
// read the object numbers to populate cache
for (i = 0; i < n; ++i) {
num = parser.getObj();
for (let i = 0; i < n; ++i) {
const num = parser.getObj();
if (!Number.isInteger(num)) {
throw new FormatError(
`invalid object number in the ObjStm stream: ${num}`);
}
nums.push(num);
var offset = parser.getObj();
const offset = parser.getObj();
if (!Number.isInteger(offset)) {
throw new FormatError(
`invalid object offset in the ObjStm stream: ${offset}`);
}
nums[i] = num;
}
const entries = new Array(n);
// read stream objects for cache
for (i = 0; i < n; ++i) {
entries.push(parser.getObj());
for (let i = 0; i < n; ++i) {
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 (isCmd(parser.buf1, 'endobj')) {
if ((parser.buf1 instanceof Cmd) && parser.buf1.cmd === 'endobj') {
parser.shift();
}
num = nums[i];
var entry = this.entries[num];
if (isStream(obj)) {
continue;
}
const num = nums[i], entry = this.entries[num];
if (entry && entry.offset === tableOffset && entry.gen === i) {
this._cacheMap.set(num, entries[i]);
this._cacheMap.set(num, obj);
}
}
xrefEntry = entries[xrefEntry.gen];
Expand Down