mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 17:48:07 +02:00
Support parsing encrypted documents in XRef.indexObjects
(issue 15893)
*Please note:* The reduced test-case is *not* a perfect reproduction of the original PDF document, since this one fails to open in e.g. Adobe Reader, but I do believe that it captures the most important points here. For corrupt *and* encrypted PDF documents, it's possible that only some trailer dictionaries actually contain an /Encrypt-entry. Previously we'd could easily miss that, since we generally pick the first not obviously corrupt trailer dictionary, and the solution implemented here is to simply pre-parse all trailer dictionaries to see if there's any /Encrypt-entries.
This commit is contained in:
parent
e36564668b
commit
7d94fdeb48
4 changed files with 35 additions and 11 deletions
|
@ -581,16 +581,11 @@ class XRef {
|
|||
this.startXRefQueue.push(xrefStm);
|
||||
this.readXRef(/* recoveryMode */ true);
|
||||
}
|
||||
// finding main trailer
|
||||
let trailerDict, trailerError;
|
||||
for (const trailer of [...trailers, "generationFallback", ...trailers]) {
|
||||
if (trailer === "generationFallback") {
|
||||
if (!trailerError) {
|
||||
break; // No need to fallback if there were no validation errors.
|
||||
}
|
||||
this._generationFallback = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
const trailerDicts = [];
|
||||
// Pre-parsing the trailers to check if the document is possibly encrypted.
|
||||
let isEncrypted = false;
|
||||
for (const trailer of trailers) {
|
||||
stream.pos = trailer;
|
||||
const parser = new Parser({
|
||||
lexer: new Lexer(stream),
|
||||
|
@ -607,6 +602,23 @@ class XRef {
|
|||
if (!(dict instanceof Dict)) {
|
||||
continue;
|
||||
}
|
||||
trailerDicts.push(dict);
|
||||
|
||||
if (dict.has("Encrypt")) {
|
||||
isEncrypted = true;
|
||||
}
|
||||
}
|
||||
|
||||
// finding main trailer
|
||||
let trailerDict, trailerError;
|
||||
for (const dict of [...trailerDicts, "genFallback", ...trailerDicts]) {
|
||||
if (dict === "genFallback") {
|
||||
if (!trailerError) {
|
||||
break; // No need to fallback if there were no validation errors.
|
||||
}
|
||||
this._generationFallback = true;
|
||||
continue;
|
||||
}
|
||||
// Do some basic validation of the trailer/root dictionary candidate.
|
||||
let validPagesDict = false;
|
||||
try {
|
||||
|
@ -628,7 +640,11 @@ class XRef {
|
|||
continue;
|
||||
}
|
||||
// taking the first one with 'ID'
|
||||
if (validPagesDict && dict.has("ID")) {
|
||||
if (
|
||||
validPagesDict &&
|
||||
(!isEncrypted || dict.has("Encrypt")) &&
|
||||
dict.has("ID")
|
||||
) {
|
||||
return dict;
|
||||
}
|
||||
// The current dictionary is a candidate, but continue searching.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue