summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorMatthew Olsson <matthewcolsson@gmail.com>2022-03-25 08:57:52 -0700
committerAndreas Kling <kling@serenityos.org>2022-03-31 18:10:45 +0200
commit49cb040c279f2003032f1f6871acd36a66a7adb4 (patch)
treeb65ca7f050b1d4fdf7c91f07fb0419e41b276fd5 /Userland/Libraries
parent4d0f74a15cff9b5e3876a5f476d92c766afc1bad (diff)
downloadserenity-49cb040c279f2003032f1f6871acd36a66a7adb4.zip
LibPDF: Fix some base-encoding-related crashes
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibPDF/Encoding.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/Userland/Libraries/LibPDF/Encoding.cpp b/Userland/Libraries/LibPDF/Encoding.cpp
index 69c45602d7..a9c4e1366a 100644
--- a/Userland/Libraries/LibPDF/Encoding.cpp
+++ b/Userland/Libraries/LibPDF/Encoding.cpp
@@ -27,14 +27,14 @@ PDFErrorOr<NonnullRefPtr<Encoding>> Encoding::from_object(Document* document, No
// Make a custom encoding
auto dict = obj->cast<DictObject>();
- // FIXME: If this entry is absent, the Differences entry shall describe differences
- // from an implicit base encoding. For a font program that is embedded in the
- // PDF file, the implicit base encoding shall be a font program's built-in
- // encoding [...]. Otherwise, for a nonsymbolic font, it shall be
- // StandardEncoding, and for a symbolic font, it shall be the font's built-in
- // encoding.
- auto base_encoding_obj = MUST(dict->get_object(document, CommonNames::BaseEncoding));
- auto base_encoding = TRY(Encoding::from_object(document, base_encoding_obj));
+ RefPtr<Encoding> base_encoding;
+ if (dict->contains(CommonNames::BaseEncoding)) {
+ auto base_encoding_obj = MUST(dict->get_object(document, CommonNames::BaseEncoding));
+ base_encoding = TRY(Encoding::from_object(document, base_encoding_obj));
+ } else {
+ base_encoding = Encoding::standard_encoding();
+ }
+
auto encoding = adopt_ref(*new Encoding());
// Build a String -> Character mapping for handling the differences map
@@ -62,8 +62,10 @@ PDFErrorOr<NonnullRefPtr<Encoding>> Encoding::from_object(Document* document, No
auto name = object->cast<NameObject>()->name();
auto character = base_encoding_name_mapping.get(name);
- VERIFY(character.has_value());
- encoding->m_descriptors.set(current_code_point, character.value());
+ // FIXME: This should always have a value. This does cause crashes in certain
+ // documents, so we must be missing something here.
+ if (character.has_value())
+ encoding->m_descriptors.set(current_code_point, character.value());
current_code_point++;
}