From 62baf25f0b04a81abaf33e409a7948a9bba5cb92 Mon Sep 17 00:00:00 2001 From: Leonardo Duarte Date: Wed, 13 Apr 2022 22:42:06 -0300 Subject: [PATCH] LibGfx: Avoid signed comparison in find_largest_image I believe the issue was caused by the product of two u16s being promoted to (signed) int, which can cause unwanted overflow behaviour when comparing to size_t. Casting each term to size_t before the multiplication makes the comparison unsigned. --- Userland/Libraries/LibGfx/ICOLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGfx/ICOLoader.cpp b/Userland/Libraries/LibGfx/ICOLoader.cpp index 0bdcb05854..fc62812fa3 100644 --- a/Userland/Libraries/LibGfx/ICOLoader.cpp +++ b/Userland/Libraries/LibGfx/ICOLoader.cpp @@ -123,7 +123,7 @@ static size_t find_largest_image(ICOLoadingContext const& context) size_t index = 0; size_t largest_index = 0; for (auto const& desc : context.images) { - if (desc.width * desc.height > max_area) { + if (static_cast(desc.width) * static_cast(desc.height) > max_area) { max_area = desc.width * desc.height; largest_index = index; }