mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Add basic validation of the 'Root' dictionary in XRef.parse
and try to recover when possible
Note that the `Catalog` constructor, and some of its methods, are already enforcing that the 'Root' dictionary is valid/well-formed. However, by doing additional validation already in `XRef.parse` there's a slightly larger chance that corrupt PDF files could be successfully parsed/rendered.
This commit is contained in:
parent
e84813e7cc
commit
346810e02a
1 changed files with 16 additions and 2 deletions
|
@ -877,8 +877,22 @@ var XRef = (function XRefClosure() {
|
|||
this.pdfManager.password);
|
||||
}
|
||||
|
||||
// get the root dictionary (catalog) object
|
||||
if (!(this.root = trailerDict.get('Root'))) {
|
||||
// Get the root dictionary (catalog) object, and do some basic validation.
|
||||
let root;
|
||||
try {
|
||||
root = trailerDict.get('Root');
|
||||
} catch (ex) {
|
||||
if (ex instanceof MissingDataException) {
|
||||
throw ex;
|
||||
}
|
||||
warn(`XRef.parse - Invalid "Root" reference: "${ex}".`);
|
||||
}
|
||||
if (isDict(root) && root.has('Pages')) {
|
||||
this.root = root;
|
||||
} else {
|
||||
if (!recoveryMode) {
|
||||
throw new XRefParseException();
|
||||
}
|
||||
throw new FormatError('Invalid root reference');
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue