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
@ -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…
x
Reference in New Issue
Block a user