Load decryption code only for encrypted PDFs

This commit is contained in:
Calixte Denizet
2026-11-20 17:28:27 +01:00
parent bc4502493f
commit bb8f1ce78a
3 changed files with 7 additions and 5 deletions
+2 -2
View File
@@ -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
View File
@@ -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
+1 -1
View File
@@ -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();