From af5a7b9a51d63467bb084e1b610efab1990fe0c6 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 23 Jul 2023 22:46:25 -0400 Subject: [PATCH] LibPDF: Don't crash on encrypted files with streams with filter arrays Makes it possible to render more than 0 pages of CIPA_DC-003-2020_E.pdf --- Userland/Libraries/LibPDF/Encryption.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibPDF/Encryption.cpp b/Userland/Libraries/LibPDF/Encryption.cpp index 2be713d8d2..f76359035f 100644 --- a/Userland/Libraries/LibPDF/Encryption.cpp +++ b/Userland/Libraries/LibPDF/Encryption.cpp @@ -676,8 +676,10 @@ void StandardSecurityHandler::crypt(NonnullRefPtr object, Reference refe }; if (stream->dict()->contains(CommonNames::Filter)) { - auto filter = stream->dict()->get_name(m_document, CommonNames::Filter).release_value_but_fixme_should_propagate_errors()->name(); - if (filter == "Crypt") + // ISO 32000 (PDF 2.0), 7.4.10 Crypt filter + // "The Crypt filter shall be the first filter in the Filter array entry." + auto filters = m_document->read_filters(stream->dict()).release_value_but_fixme_should_propagate_errors(); + if (!filters.is_empty() && filters[0] == "Crypt") TODO(); } } else if (object->is()) {