From 10575fea9fbef2a9c7d65f2ba26cae2b96da5501 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 18 Feb 2023 16:20:27 +0100 Subject: [PATCH] LibGfx: Fix sign-compare compile error in TGALoader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I'm not sure why this isn't caught on other people's setups or CI, but when building on NixOS it fails with: error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Werror=sign-compare] --- Userland/Libraries/LibGfx/TGALoader.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/TGALoader.cpp b/Userland/Libraries/LibGfx/TGALoader.cpp index f6928d6985..067299454a 100644 --- a/Userland/Libraries/LibGfx/TGALoader.cpp +++ b/Userland/Libraries/LibGfx/TGALoader.cpp @@ -209,7 +209,8 @@ bool TGAImageDecoderPlugin::decode_tga_header() auto bytes_remaining = reader->data().size() - reader->index(); - if (m_context->header.data_type_code == TGADataType::UncompressedRGB && bytes_remaining < (m_context->header.width * m_context->header.height * (m_context->header.bits_per_pixel / 8))) + // FIXME: Check for multiplication overflow! + if (m_context->header.data_type_code == TGADataType::UncompressedRGB && bytes_remaining < static_cast(m_context->header.width * m_context->header.height * (m_context->header.bits_per_pixel / 8))) return false; if (m_context->header.bits_per_pixel < 8 || m_context->header.bits_per_pixel > 32) @@ -228,7 +229,8 @@ ErrorOr TGAImageDecoderPlugin::validate_before_create(ReadonlyBytes data) if (data.size() < sizeof(TGAHeader)) return false; TGAHeader const& header = *reinterpret_cast(data.data()); - if (header.data_type_code == TGADataType::UncompressedRGB && data.size() < (header.width * header.height * (header.bits_per_pixel / 8))) + // FIXME: Check for multiplication overflow! + if (header.data_type_code == TGADataType::UncompressedRGB && data.size() < static_cast(header.width * header.height * (header.bits_per_pixel / 8))) return false; if (header.bits_per_pixel < 8 || header.bits_per_pixel > 32) return false;