From b1d148a4aa22538682468e66f178d51f033dcb83 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 2 Sep 2015 17:05:34 +0200 Subject: [PATCH] Remove `Parser_fetchIfRef` since it's obsolete This code was added in PR 1214, but was made obsolete by PRs 1488/1493. Prior to the latter ones, `Dict_get` retured the raw objects. However, afterwards (and currently) `Dict_get` now resolves indirect objects, which makes `Parser_fetchIfRef` redundant. *Potential risks with this patch:* This patch passes all tests locally, but there's a *small* possibility that it could break some weird PDF files. In the current code, wrapping `Dict_get` inside `Parser_fetchIfRef` will potentially mean two back-to-back call of `XRef_fetch`, if a reference points directly to another reference. I'm not sure if this can actually happen in practice, and I'd think that if that were the case we'd already have run into it elsewhere in the code-base, given that `Parser` is the only place where we try to "double" resolve references. --- src/core/parser.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/core/parser.js b/src/core/parser.js index 48a615de9..9ee842b76 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -341,7 +341,7 @@ var Parser = (function ParserClosure() { var stream = lexer.stream; // Parse dictionary. - var dict = new Dict(null); + var dict = new Dict(this.xref); while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) { if (!isName(this.buf1)) { error('Dictionary key must be a name object'); @@ -355,7 +355,7 @@ var Parser = (function ParserClosure() { } // Extract the name of the first (i.e. the current) image filter. - var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName; + var filter = dict.get('Filter', 'F'), filterName; if (isName(filter)) { filterName = filter.name; } else if (isArray(filter) && isName(filter[0])) { @@ -416,10 +416,6 @@ var Parser = (function ParserClosure() { return imageStream; }, - fetchIfRef: function Parser_fetchIfRef(obj) { - // not relying on the xref.fetchIfRef -- xref might not be set - return (isRef(obj) ? this.xref.fetch(obj) : obj); - }, makeStream: function Parser_makeStream(dict, cipherTransform) { var lexer = this.lexer; var stream = lexer.stream; @@ -429,7 +425,7 @@ var Parser = (function ParserClosure() { var pos = stream.pos - 1; // get length - var length = this.fetchIfRef(dict.get('Length')); + var length = dict.get('Length'); if (!isInt(length)) { info('Bad ' + length + ' attribute in stream'); length = 0; @@ -499,8 +495,8 @@ var Parser = (function ParserClosure() { return stream; }, filter: function Parser_filter(stream, dict, length) { - var filter = this.fetchIfRef(dict.get('Filter', 'F')); - var params = this.fetchIfRef(dict.get('DecodeParms', 'DP')); + var filter = dict.get('Filter', 'F'); + var params = dict.get('DecodeParms', 'DP'); if (isName(filter)) { return this.makeFilter(stream, filter.name, length, params); } @@ -532,8 +528,8 @@ var Parser = (function ParserClosure() { return new NullStream(stream); } try { - if (params) { - params = this.fetchIfRef(params); + if (params && this.xref) { + params = this.xref.fetchIfRef(params); } var xrefStreamStats = this.xref.stats.streamTypes; if (name === 'FlateDecode' || name === 'Fl') {