mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #14338 from Snuffleupagus/XRef-more-Pages-validation
[api-minor] Clear all caches in `XRef.indexObjects`, and improve /Root dictionary validation in `XRef.parse` (issue 14303)
This commit is contained in:
commit
335c4c8a43
2 changed files with 66 additions and 43 deletions
|
@ -107,14 +107,26 @@ class XRef {
|
|||
}
|
||||
warn(`XRef.parse - Invalid "Root" reference: "${ex}".`);
|
||||
}
|
||||
if (root instanceof Dict && root.has("Pages")) {
|
||||
this.root = root;
|
||||
} else {
|
||||
if (!recoveryMode) {
|
||||
throw new XRefParseException();
|
||||
if (root instanceof Dict) {
|
||||
try {
|
||||
const pages = root.get("Pages");
|
||||
if (pages instanceof Dict) {
|
||||
this.root = root;
|
||||
return;
|
||||
}
|
||||
} catch (ex) {
|
||||
if (ex instanceof MissingDataException) {
|
||||
throw ex;
|
||||
}
|
||||
warn(`XRef.parse - Invalid "Pages" reference: "${ex}".`);
|
||||
}
|
||||
throw new FormatError("Invalid root reference");
|
||||
}
|
||||
|
||||
if (!recoveryMode) {
|
||||
throw new XRefParseException();
|
||||
}
|
||||
// Even recovery failed, there's nothing more we can do here.
|
||||
throw new InvalidPDFException("Invalid Root reference.");
|
||||
}
|
||||
|
||||
processXRefTable(parser) {
|
||||
|
@ -417,6 +429,7 @@ class XRef {
|
|||
|
||||
// Clear out any existing entries, since they may be bogus.
|
||||
this.entries.length = 0;
|
||||
this._cacheMap.clear();
|
||||
|
||||
const stream = this.stream;
|
||||
stream.pos = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue