Improve PDFDocument.checkLastPage
for documents with corrupt XRef tables (PR 14311, 14335 follow-up)
Rather than trying, and failing, to fetch the entire /Pages-tree for documents with corrupt XRef tables, let's fallback to indexing all objects *before* trying to invoke the `Catalog.getAllPageDicts` method.
This commit is contained in:
parent
97dc048e56
commit
47f9eef584
@ -1344,7 +1344,7 @@ class PDFDocument {
|
|||||||
// Clear out the various caches to ensure that we haven't stored any
|
// Clear out the various caches to ensure that we haven't stored any
|
||||||
// inconsistent and/or incorrect state, since that could easily break
|
// inconsistent and/or incorrect state, since that could easily break
|
||||||
// subsequent `this.getPage` calls.
|
// subsequent `this.getPage` calls.
|
||||||
this._pagePromises.clear();
|
this._pagePromises.delete(0);
|
||||||
await this.cleanup();
|
await this.cleanup();
|
||||||
|
|
||||||
throw new XRefParseException();
|
throw new XRefParseException();
|
||||||
@ -1380,20 +1380,23 @@ class PDFDocument {
|
|||||||
}
|
}
|
||||||
await this.getPage(numPages - 1);
|
await this.getPage(numPages - 1);
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
warn(`checkLastPage - invalid /Pages tree /Count: ${numPages}.`);
|
|
||||||
// Clear out the various caches to ensure that we haven't stored any
|
// Clear out the various caches to ensure that we haven't stored any
|
||||||
// inconsistent and/or incorrect state, since that could easily break
|
// inconsistent and/or incorrect state, since that could easily break
|
||||||
// subsequent `this.getPage` calls.
|
// subsequent `this.getPage` calls.
|
||||||
|
this._pagePromises.delete(numPages - 1);
|
||||||
await this.cleanup();
|
await this.cleanup();
|
||||||
|
|
||||||
|
if (reason instanceof XRefEntryException && !recoveryMode) {
|
||||||
|
throw new XRefParseException();
|
||||||
|
}
|
||||||
|
warn(`checkLastPage - invalid /Pages tree /Count: ${numPages}.`);
|
||||||
|
|
||||||
let pagesTree;
|
let pagesTree;
|
||||||
try {
|
try {
|
||||||
pagesTree = await pdfManager.ensureCatalog("getAllPageDicts");
|
pagesTree = await pdfManager.ensureCatalog("getAllPageDicts");
|
||||||
} catch (reasonAll) {
|
} catch (reasonAll) {
|
||||||
if (reasonAll instanceof XRefEntryException) {
|
if (reasonAll instanceof XRefEntryException && !recoveryMode) {
|
||||||
if (!recoveryMode) {
|
throw new XRefParseException();
|
||||||
throw new XRefParseException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catalog.setActualNumPages(1);
|
catalog.setActualNumPages(1);
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user