Truly independent web browser
LibGfx: Reject BMPs with an unrepresentable height
Andreas Klinga3f34213ea93
diff --git a/Libraries/LibGfx/ImageFormats/BMPLoader.cpp b/Libraries/LibGfx/ImageFormats/BMPLoader.cppindex f74f5484b3e..52be8d005ae 100644--- a/Libraries/LibGfx/ImageFormats/BMPLoader.cpp+++ b/Libraries/LibGfx/ImageFormats/BMPLoader.cpp@@ -11,6 +11,7 @@#include <AK/Debug.h>#include <AK/Error.h>#include <AK/Function.h>+#include <AK/NumericLimits.h>#include <AK/Try.h>#include <AK/Vector.h>#include <LibGfx/ImageFormats/BMPLoader.h>@@ -565,6 +566,10 @@ static bool decode_bmp_core_dib(BMPLoadingContext& context, InputStreamer& streadbgln("BMP has a negative width: {}", core.width);return false;}+ if (core.height == NumericLimits<i32>::min()) {+ dbgln("BMP has an invalid height: {}", core.height);+ return false;+ }auto color_planes = streamer.read_u16();if (color_planes != 1) {@@ -615,6 +620,10 @@ static bool decode_bmp_osv2_dib(BMPLoadingContext& context, InputStreamer& streadbgln("BMP has a negative width: {}", core.width);return false;}+ if (core.height == NumericLimits<i32>::min()) {+ dbgln("BMP has an invalid height: {}", core.height);+ return false;+ }auto color_planes = streamer.read_u16();if (color_planes != 1) {diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cppindex bcc110e5872..3ab690ca28a 100644--- a/Tests/LibGfx/TestImageDecoder.cpp+++ b/Tests/LibGfx/TestImageDecoder.cpp@@ -202,8 +202,7 @@ TEST_CASE(test_bmp_v4)TEST_CASE(test_bmp_negative_int_min_height){auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("bmp/negative-height-int-min.bmp"sv)));- auto plugin_decoder = TRY_OR_FAIL(Gfx::BMPImageDecoderPlugin::create(file->bytes()));- EXPECT(plugin_decoder->frame(0).is_error());+ EXPECT(Gfx::BMPImageDecoderPlugin::create(file->bytes()).is_error());}TEST_CASE(test_bmp_v5_icc_profile_out_of_bounds)