diff --git a/Userland/Libraries/LibGfx/CMYKBitmap.cpp b/Userland/Libraries/LibGfx/CMYKBitmap.cpp index bc1822035b..b052b3c935 100644 --- a/Userland/Libraries/LibGfx/CMYKBitmap.cpp +++ b/Userland/Libraries/LibGfx/CMYKBitmap.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include namespace Gfx { @@ -11,7 +12,12 @@ namespace Gfx { ErrorOr> CMYKBitmap::create_with_size(IntSize const& size) { VERIFY(size.width() >= 0 && size.height() >= 0); - auto data = TRY(ByteBuffer::create_uninitialized(size.width() * size.height() * sizeof(CMYK))); + Checked final_size { size.width() }; + final_size.mul(size.height()); + final_size.mul(sizeof(CMYK)); + if (final_size.has_overflow()) + return Error::from_string_literal("Image dimensions cause an integer overflow"); + auto data = TRY(ByteBuffer::create_uninitialized(final_size.value())); return adopt_ref(*new CMYKBitmap(size, move(data))); }