diff --git a/Userland/Libraries/LibGfx/ImageFormats/TGALoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/TGALoader.cpp index 6b4f502404..d194b703bc 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/TGALoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/TGALoader.cpp @@ -174,11 +174,11 @@ IntSize TGAImageDecoderPlugin::size() return IntSize { m_context->header.width, m_context->header.height }; } -bool TGAImageDecoderPlugin::decode_tga_header() +ErrorOr TGAImageDecoderPlugin::decode_tga_header() { auto& reader = m_context->reader; if (reader->data().size() < sizeof(TGAHeader)) - return false; + return Error::from_string_literal("Not enough data to be a TGA image"); m_context->header.id_length = reader->read_u8(); m_context->header.color_map_type = reader->read_u8(); @@ -197,19 +197,17 @@ bool TGAImageDecoderPlugin::decode_tga_header() // 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; + return Error::from_string_literal("Not enough data to read an image with the expected size"); if (m_context->header.bits_per_pixel < 8 || m_context->header.bits_per_pixel > 32) - return false; + return Error::from_string_literal("Invalid bit depth"); - return true; + return {}; } ErrorOr TGAImageDecoderPlugin::initialize() { - if (decode_tga_header()) - return {}; - return Error::from_string_literal("Bad TGA header"); + return decode_tga_header(); } ErrorOr TGAImageDecoderPlugin::validate_before_create(ReadonlyBytes data) diff --git a/Userland/Libraries/LibGfx/ImageFormats/TGALoader.h b/Userland/Libraries/LibGfx/ImageFormats/TGALoader.h index 4c7d1b2cf7..472016fe4f 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/TGALoader.h +++ b/Userland/Libraries/LibGfx/ImageFormats/TGALoader.h @@ -31,7 +31,7 @@ public: virtual ErrorOr> icc_data() override; private: - bool decode_tga_header(); + ErrorOr decode_tga_header(); OwnPtr m_context; };