From a20393e6e447d14eb5f29fd6608457b8355d12c1 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 29 Dec 2021 13:13:42 +0100 Subject: [PATCH] Update `PDFDocument._getLinearizationPage` to do the /Type-check correctly (PR 14400 follow-up) I forgot about this in PR 14400, since we should obviously be consistent *and* given that the existing check is actually wrong; sorry about this! --- src/core/document.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/core/document.js b/src/core/document.js index d2238cae9..5daeeb186 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -1264,7 +1264,7 @@ class PDFDocument { } async _getLinearizationPage(pageIndex) { - const { catalog, linearization } = this; + const { catalog, linearization, xref } = this; if ( typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || TESTING") @@ -1277,22 +1277,25 @@ class PDFDocument { const ref = Ref.get(linearization.objectNumberFirst, 0); try { - const obj = await this.xref.fetchAsync(ref); + const obj = await xref.fetchAsync(ref); // Ensure that the object that was found is actually a Page dictionary. - if ( - isDict(obj, "Page") || - (isDict(obj) && !obj.has("Type") && obj.has("Contents")) - ) { - if (ref && !catalog.pageKidsCountCache.has(ref)) { - catalog.pageKidsCountCache.put(ref, 1); // Cache the Page reference. + if (obj instanceof Dict) { + let type = obj.getRaw("Type"); + if (type instanceof Ref) { + type = await xref.fetchAsync(type); + } + if (isName(type, "Page") || (!obj.has("Type") && !obj.has("Kids"))) { + if (ref && !catalog.pageKidsCountCache.has(ref)) { + catalog.pageKidsCountCache.put(ref, 1); // Cache the Page reference. + } + return [obj, ref]; } - return [obj, ref]; } throw new FormatError( "The Linearization dictionary doesn't point to a valid Page dictionary." ); } catch (reason) { - info(reason); + warn(`_getLinearizationPage: "${reason.message}".`); return catalog.getPageDict(pageIndex); } }