From 104484430775b066f953e1a3035d466b813fbddc Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 25 Jan 2023 21:41:22 -0500 Subject: [PATCH] LibGfx: Enforce type of 'cprt' and 'desc' type in v4 files Add a targeted quirk for the one known file where this is violated. Adding that quirk is a bit of a bummer, since that means all client code of this class now needs to deal with the possibility that 'cprt' and 'desc' aren't 'mluc' for v4 files. But if that code wants to handle v2 files, it needs to deal with that anyways, so it's really just a bit of a bummer and not more. --- Userland/Libraries/LibGfx/ICCProfile.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibGfx/ICCProfile.cpp b/Userland/Libraries/LibGfx/ICCProfile.cpp index 8b8b2896f3..cab11172ea 100644 --- a/Userland/Libraries/LibGfx/ICCProfile.cpp +++ b/Userland/Libraries/LibGfx/ICCProfile.cpp @@ -1223,6 +1223,9 @@ ErrorOr Profile::check_tag_types() // This uses m_tag_table.get() even for tags that are guaranteed to exist after check_required_tags() // so that the two functions can be called in either order. + // Profile ID of /System/Library/ColorSync/Profiles/ITU-2020.icc on macOS 13.1. + static constexpr Crypto::Hash::MD5::DigestType apple_itu_2020_id = { 0x57, 0x0b, 0x1b, 0x76, 0xc6, 0xa0, 0x50, 0xaa, 0x9f, 0x6c, 0x53, 0x8d, 0xbe, 0x2d, 0x3e, 0xf0 }; + // ICC v4, 9.2.1 AToB0Tag // "Permitted tag types: lut8Type or lut16Type or lutAToBType" // FIXME @@ -1331,9 +1334,10 @@ ErrorOr Profile::check_tag_types() if (auto type = m_tag_table.get(copyrightTag); type.has_value()) { // The v4 spec requires multiLocalizedUnicodeType for this, but I'm aware of a single file // that still uses the v2 'text' type here: /System/Library/ColorSync/Profiles/ITU-2020.icc on macOS 13.1. - // FIXME: File a bug for that and add id-based quirk instead. - // if (is_v4() && type.value()->type() != MultiLocalizedUnicodeTagData::Type) - // return Error::from_string_literal("ICC::Profile: copyrightTag has unexpected v4 type"); + // https://openradar.appspot.com/radar?id=5529765549178880 + bool has_v2_cprt_type_in_v4_file_quirk = id() == apple_itu_2020_id; + if (is_v4() && type.value()->type() != MultiLocalizedUnicodeTagData::Type && (!has_v2_cprt_type_in_v4_file_quirk || type.value()->type() != TextTagData::Type)) + return Error::from_string_literal("ICC::Profile: copyrightTag has unexpected v4 type"); if (is_v2() && type.value()->type() != TextTagData::Type) return Error::from_string_literal("ICC::Profile: copyrightTag has unexpected v2 type"); } @@ -1494,9 +1498,10 @@ ErrorOr Profile::check_tag_types() if (auto type = m_tag_table.get(profileDescriptionTag); type.has_value()) { // The v4 spec requires multiLocalizedUnicodeType for this, but I'm aware of a single file // that still uses the v2 'desc' type here: /System/Library/ColorSync/Profiles/ITU-2020.icc on macOS 13.1. - // FIXME: File a bug for that and add id-based quirk instead. - // if (is_v4() && type.value()->type() != MultiLocalizedUnicodeTagData::Type) - // return Error::from_string_literal("ICC::Profile: profileDescriptionTag has unexpected v4 type"); + // https://openradar.appspot.com/radar?id=5529765549178880 + bool has_v2_desc_type_in_v4_file_quirk = id() == apple_itu_2020_id; + if (is_v4() && type.value()->type() != MultiLocalizedUnicodeTagData::Type && (!has_v2_desc_type_in_v4_file_quirk || type.value()->type() != TextDescriptionTagData::Type)) + return Error::from_string_literal("ICC::Profile: profileDescriptionTag has unexpected v4 type"); if (is_v2() && type.value()->type() != TextDescriptionTagData::Type) return Error::from_string_literal("ICC::Profile: profileDescriptionTag has unexpected v2 type"); }