diff --git a/src/core/xref.js b/src/core/xref.js index d75b899b9..e273eeeba 100644 --- a/src/core/xref.js +++ b/src/core/xref.js @@ -582,6 +582,7 @@ class XRef { continue; } // Do some basic validation of the trailer/root dictionary candidate. + let validPagesDict = false; try { const rootDict = dict.get("Root"); if (!(rootDict instanceof Dict)) { @@ -591,13 +592,17 @@ class XRef { if (!(pagesDict instanceof Dict)) { continue; } + const pagesCount = pagesDict.get("Count"); + if (Number.isInteger(pagesCount)) { + validPagesDict = true; + } // The top-level /Pages dictionary isn't obviously corrupt. } catch (ex) { trailerError = ex; continue; } // taking the first one with 'ID' - if (dict.has("ID")) { + if (validPagesDict && dict.has("ID")) { return dict; } // The current dictionary is a candidate, but continue searching. diff --git a/test/driver.js b/test/driver.js index 9af37977c..eb51d3909 100644 --- a/test/driver.js +++ b/test/driver.js @@ -553,11 +553,7 @@ class Driver { if (!task.pdfDoc) { return task.firstPage || 1; } - let lastPageNumber = task.lastPage || 0; - if (!lastPageNumber || lastPageNumber > task.pdfDoc.numPages) { - lastPageNumber = task.pdfDoc.numPages; - } - return lastPageNumber; + return task.lastPage || task.pdfDoc.numPages; } _nextPage(task, loadError) {