From f8a3022ca2a056bbf524209f1da19b1d789d54d0 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 19 Jul 2023 21:25:37 -0400 Subject: [PATCH] LibPDF: Plumb OE, UE, Perms values to StandardSecurityHandler --- Userland/Libraries/LibPDF/CommonNames.h | 3 +++ Userland/Libraries/LibPDF/Encryption.cpp | 18 ++++++++++++++++-- Userland/Libraries/LibPDF/Encryption.h | 5 ++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibPDF/CommonNames.h b/Userland/Libraries/LibPDF/CommonNames.h index 9bba2e78d4..7e3ae1a3fa 100644 --- a/Userland/Libraries/LibPDF/CommonNames.h +++ b/Userland/Libraries/LibPDF/CommonNames.h @@ -111,6 +111,7 @@ A(Names) \ A(Next) \ A(O) \ + A(OE) \ A(OP) \ A(OPM) \ A(Ordering) \ @@ -119,6 +120,7 @@ A(Pages) \ A(Parent) \ A(Pattern) \ + A(Perms) \ A(Predictor) \ A(Prev) \ A(Producer) \ @@ -146,6 +148,7 @@ A(Type) \ A(Type1C) \ A(U) \ + A(UE) \ A(UCR) \ A(UseBlackPTComp) \ A(UserUnit) \ diff --git a/Userland/Libraries/LibPDF/Encryption.cpp b/Userland/Libraries/LibPDF/Encryption.cpp index 95735e9db1..3a65d8faf5 100644 --- a/Userland/Libraries/LibPDF/Encryption.cpp +++ b/Userland/Libraries/LibPDF/Encryption.cpp @@ -166,7 +166,12 @@ PDFErrorOr> StandardSecurityHandler::crea if (encryption_dict->contains(CommonNames::EncryptMetadata)) encryption_dict->get_value(CommonNames::EncryptMetadata).get(); + DeprecatedString oe, ue, perms; if (v >= 5) { + oe = TRY(encryption_dict->get_string(document, CommonNames::OE))->string(); + ue = TRY(encryption_dict->get_string(document, CommonNames::UE))->string(); + perms = TRY(encryption_dict->get_string(document, CommonNames::Perms))->string(); + // O and U are 48 bytes for V == 5, but some files pad them with nul bytes to 127 bytes. So trim them, if necessary. if (o.length() > 48) o = o.substring(0, 48); @@ -175,18 +180,27 @@ PDFErrorOr> StandardSecurityHandler::crea if (o.length() != 48) return Error(Error::Type::Parse, "Invalid O size"); + if (oe.length() != 32) + return Error(Error::Type::Parse, "Invalid OE size"); if (u.length() != 48) return Error(Error::Type::Parse, "Invalid U size"); + if (ue.length() != 32) + return Error(Error::Type::Parse, "Invalid UE size"); + if (perms.length() != 16) + return Error(Error::Type::Parse, "Invalid Perms size"); } - return adopt_ref(*new StandardSecurityHandler(document, revision, o, u, p, encrypt_metadata, length, method)); + return adopt_ref(*new StandardSecurityHandler(document, revision, o, oe, u, ue, perms, p, encrypt_metadata, length, method)); } -StandardSecurityHandler::StandardSecurityHandler(Document* document, size_t revision, DeprecatedString const& o_entry, DeprecatedString const& u_entry, u32 flags, bool encrypt_metadata, size_t length, CryptFilterMethod method) +StandardSecurityHandler::StandardSecurityHandler(Document* document, size_t revision, DeprecatedString const& o_entry, DeprecatedString const& oe_entry, DeprecatedString const& u_entry, DeprecatedString const& ue_entry, DeprecatedString const& perms_entry, u32 flags, bool encrypt_metadata, size_t length, CryptFilterMethod method) : m_document(document) , m_revision(revision) , m_o_entry(o_entry) + , m_oe_entry(oe_entry) , m_u_entry(u_entry) + , m_ue_entry(ue_entry) + , m_perms_entry(perms_entry) , m_flags(flags) , m_encrypt_metadata(encrypt_metadata) , m_length(length) diff --git a/Userland/Libraries/LibPDF/Encryption.h b/Userland/Libraries/LibPDF/Encryption.h index c0f404346e..07f37a083a 100644 --- a/Userland/Libraries/LibPDF/Encryption.h +++ b/Userland/Libraries/LibPDF/Encryption.h @@ -39,7 +39,7 @@ class StandardSecurityHandler : public SecurityHandler { public: static PDFErrorOr> create(Document*, NonnullRefPtr encryption_dict); - StandardSecurityHandler(Document*, size_t revision, DeprecatedString const& o_entry, DeprecatedString const& u_entry, u32 flags, bool encrypt_metadata, size_t length, CryptFilterMethod method); + StandardSecurityHandler(Document*, size_t revision, DeprecatedString const& o_entry, DeprecatedString const& oe_entry, DeprecatedString const& u_entry, DeprecatedString const& ue_entry, DeprecatedString const& perms, u32 flags, bool encrypt_metadata, size_t length, CryptFilterMethod method); ~StandardSecurityHandler() override = default; @@ -74,7 +74,10 @@ private: size_t m_revision; Optional m_encryption_key; DeprecatedString m_o_entry; + DeprecatedString m_oe_entry; DeprecatedString m_u_entry; + DeprecatedString m_ue_entry; + DeprecatedString m_perms_entry; u32 m_flags; bool m_encrypt_metadata; size_t m_length;