From 1668d0da2718500519575cb8eddf9754866dea3a Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 5 Feb 2023 09:14:08 -0500 Subject: [PATCH] LibGfx: Extract a variable in ICC TextDescriptionTagData --- Userland/Libraries/LibGfx/ICC/TagTypes.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/ICC/TagTypes.cpp b/Userland/Libraries/LibGfx/ICC/TagTypes.cpp index e569f01e9a..aa73e992ed 100644 --- a/Userland/Libraries/LibGfx/ICC/TagTypes.cpp +++ b/Userland/Libraries/LibGfx/ICC/TagTypes.cpp @@ -391,11 +391,12 @@ ErrorOr> TextDescriptionTagData::from_byte // filled in as 0, with no data placed in the Unicode localizable profile description area. Optional unicode_description; if (unicode_description_length > 0) { - u16 last_code_point = (u16)(unicode_description_data[2 * (unicode_description_length - 1)] << 8) | (u16)unicode_description_data[2 * (unicode_description_length - 1) + 1]; + u32 byte_size_without_nul = 2 * (unicode_description_length - 1); + u16 last_code_point = (u16)(unicode_description_data[byte_size_without_nul] << 8) | (u16)unicode_description_data[byte_size_without_nul + 1]; if (last_code_point != 0) return Error::from_string_literal("ICC::Profile: textDescriptionType Unicode description not \\0-terminated"); - StringView utf_16be_data { unicode_description_data, 2 * (unicode_description_length - 1) }; + StringView utf_16be_data { unicode_description_data, byte_size_without_nul }; unicode_description = TRY(String::from_deprecated_string(TextCodec::decoder_for("utf-16be")->to_utf8(utf_16be_data))); }