From f87d93b4ee4c2ba910a520bd7ab633c27cc0ee20 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 11 Nov 2023 11:17:43 +0000 Subject: [PATCH] LibGfx/ICC: Ensure Macintosh ScriptCode length is within expected range Previously, it was possible for a `TextDescriptionTagData` object with an incorrect Macintosh ScriptCode description length to cause a buffer overflow. --- Userland/Libraries/LibGfx/ICC/TagTypes.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGfx/ICC/TagTypes.cpp b/Userland/Libraries/LibGfx/ICC/TagTypes.cpp index 5fe20b5fce..f68c5eee1c 100644 --- a/Userland/Libraries/LibGfx/ICC/TagTypes.cpp +++ b/Userland/Libraries/LibGfx/ICC/TagTypes.cpp @@ -1151,7 +1151,10 @@ ErrorOr> TextDescriptionTagData::from_byte u8 macintosh_description_length = *cursor; cursor += 1; - if (macintosh_description_length > 67) + Checked macintosh_description_end = unicode_desciption_end; + macintosh_description_end += 3; + macintosh_description_end += macintosh_description_length; + if (macintosh_description_length > 67 || macintosh_description_end.has_overflow() || macintosh_description_end.value() > bytes.size()) return Error::from_string_literal("ICC::Profile: textDescriptionType ScriptCode description too long"); u8 const* macintosh_description_data = cursor;