Restore a weaker version of the /Pages dictionary /Count check for corrupt documents (PR 15593 follow-up)
It appears that PR 15593 broke `issue12402`, and we thus need to partially restore the /Count check. I completely missed this when looking at the test-results for PR 15593, both locally and on the bots, since the `Driver._getLastPageNumber` method would "swallow" an unavailable page number.
This commit is contained in:
parent
36967fcedb
commit
e591378ff1
@ -582,6 +582,7 @@ class XRef {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Do some basic validation of the trailer/root dictionary candidate.
|
// Do some basic validation of the trailer/root dictionary candidate.
|
||||||
|
let validPagesDict = false;
|
||||||
try {
|
try {
|
||||||
const rootDict = dict.get("Root");
|
const rootDict = dict.get("Root");
|
||||||
if (!(rootDict instanceof Dict)) {
|
if (!(rootDict instanceof Dict)) {
|
||||||
@ -591,13 +592,17 @@ class XRef {
|
|||||||
if (!(pagesDict instanceof Dict)) {
|
if (!(pagesDict instanceof Dict)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
const pagesCount = pagesDict.get("Count");
|
||||||
|
if (Number.isInteger(pagesCount)) {
|
||||||
|
validPagesDict = true;
|
||||||
|
}
|
||||||
// The top-level /Pages dictionary isn't obviously corrupt.
|
// The top-level /Pages dictionary isn't obviously corrupt.
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
trailerError = ex;
|
trailerError = ex;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// taking the first one with 'ID'
|
// taking the first one with 'ID'
|
||||||
if (dict.has("ID")) {
|
if (validPagesDict && dict.has("ID")) {
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
// The current dictionary is a candidate, but continue searching.
|
// The current dictionary is a candidate, but continue searching.
|
||||||
|
@ -553,11 +553,7 @@ class Driver {
|
|||||||
if (!task.pdfDoc) {
|
if (!task.pdfDoc) {
|
||||||
return task.firstPage || 1;
|
return task.firstPage || 1;
|
||||||
}
|
}
|
||||||
let lastPageNumber = task.lastPage || 0;
|
return task.lastPage || task.pdfDoc.numPages;
|
||||||
if (!lastPageNumber || lastPageNumber > task.pdfDoc.numPages) {
|
|
||||||
lastPageNumber = task.pdfDoc.numPages;
|
|
||||||
}
|
|
||||||
return lastPageNumber;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_nextPage(task, loadError) {
|
_nextPage(task, loadError) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user