1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-19 12:57:39 +00:00

LibPDF: Fix some base-encoding-related crashes

This commit is contained in:
Matthew Olsson 2022-03-25 08:57:52 -07:00 committed by Andreas Kling
parent 4d0f74a15c
commit 49cb040c27

View file

@ -27,14 +27,14 @@ PDFErrorOr<NonnullRefPtr<Encoding>> Encoding::from_object(Document* document, No
// Make a custom encoding // Make a custom encoding
auto dict = obj->cast<DictObject>(); auto dict = obj->cast<DictObject>();
// FIXME: If this entry is absent, the Differences entry shall describe differences RefPtr<Encoding> base_encoding;
// from an implicit base encoding. For a font program that is embedded in the if (dict->contains(CommonNames::BaseEncoding)) {
// PDF file, the implicit base encoding shall be a font program's built-in auto base_encoding_obj = MUST(dict->get_object(document, CommonNames::BaseEncoding));
// encoding [...]. Otherwise, for a nonsymbolic font, it shall be base_encoding = TRY(Encoding::from_object(document, base_encoding_obj));
// StandardEncoding, and for a symbolic font, it shall be the font's built-in } else {
// encoding. base_encoding = Encoding::standard_encoding();
auto base_encoding_obj = MUST(dict->get_object(document, CommonNames::BaseEncoding)); }
auto base_encoding = TRY(Encoding::from_object(document, base_encoding_obj));
auto encoding = adopt_ref(*new Encoding()); auto encoding = adopt_ref(*new Encoding());
// Build a String -> Character mapping for handling the differences map // 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 name = object->cast<NameObject>()->name();
auto character = base_encoding_name_mapping.get(name); auto character = base_encoding_name_mapping.get(name);
VERIFY(character.has_value()); // FIXME: This should always have a value. This does cause crashes in certain
encoding->m_descriptors.set(current_code_point, character.value()); // documents, so we must be missing something here.
if (character.has_value())
encoding->m_descriptors.set(current_code_point, character.value());
current_code_point++; current_code_point++;
} }