mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-11-30 16:37:18 +01:00
Load decryption code only for encrypted PDFs
This commit is contained in:
@@ -1104,8 +1104,8 @@ class PDFDocument {
|
||||
});
|
||||
}
|
||||
|
||||
parse(recoveryMode) {
|
||||
this.xref.parse(recoveryMode);
|
||||
async parse(recoveryMode) {
|
||||
await this.xref.parse(recoveryMode);
|
||||
this.catalog = new Catalog(this.pdfManager, this.xref);
|
||||
this.xfaFactory = null;
|
||||
}
|
||||
|
||||
+4
-2
@@ -30,7 +30,6 @@ import {
|
||||
XRefParseException,
|
||||
} from "./core_utils.js";
|
||||
import { BaseStream } from "./base_stream.js";
|
||||
import { CipherTransformFactory } from "./crypto.js";
|
||||
|
||||
class XRef {
|
||||
#cacheMap = new Map();
|
||||
@@ -116,7 +115,7 @@ class XRef {
|
||||
this.startXRefQueue = [startXRef];
|
||||
}
|
||||
|
||||
parse(recoveryMode = false) {
|
||||
async parse(recoveryMode = false) {
|
||||
this.#parsedWithRecovery = recoveryMode;
|
||||
let trailerDict;
|
||||
if (!recoveryMode) {
|
||||
@@ -140,6 +139,9 @@ class XRef {
|
||||
if (encrypt instanceof Dict) {
|
||||
const ids = trailerDict.get("ID");
|
||||
const fileId = ids?.length ? ids[0] : "";
|
||||
const { CipherTransformFactory } = await import(
|
||||
/* webpackChunkName: "crypto" */ "./crypto.js"
|
||||
);
|
||||
// The 'Encrypt' dictionary itself should not be encrypted, and by
|
||||
// setting `suppressEncryption` we can prevent an infinite loop inside
|
||||
// of `XRef_fetchUncompressed` if the dictionary contains indirect
|
||||
|
||||
@@ -381,7 +381,7 @@ describe("CFFParser", function () {
|
||||
};
|
||||
const pdfDocument = new PDFDocument(pdfManager, new Stream(data));
|
||||
pdfDocument.parseStartXRef();
|
||||
pdfDocument.xref.parse();
|
||||
await pdfDocument.xref.parse();
|
||||
|
||||
// Object 8 is the `/FontFile3` (`/CIDFontType0C`) stream in the fixture.
|
||||
const fontProgram = pdfDocument.xref.fetch(Ref.get(8, 0)).getBytes();
|
||||
|
||||
Reference in New Issue
Block a user