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

Restore a weaker version of the /Pages dictionary /Count check for corrupt documents (PR 15593 follow-up) #15603

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion src/core/xref.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions test/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down