1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 17:44:56 +09:00

LibGfx: Properly skip color masks in BMP V2+ headers

Color masks should only be used when the compression type is either
BITFIELDS or ALPHABITFIELDS. They were always read before and produced
corrupted images when there was random data in the mask fields.
This commit is contained in:
aplefull 2025-05-06 01:58:09 +02:00 committed by Jelle Raaijmakers
parent c908c14aac
commit 48ca895f5f
Notes: github-actions[bot] 2025-05-09 19:49:34 +00:00
3 changed files with 15 additions and 0 deletions

View file

@ -724,6 +724,11 @@ static bool decode_bmp_v2_dib(BMPLoadingContext& context, InputStreamer& streame
if (!decode_bmp_info_dib(context, streamer))
return false;
if (context.dib.info.compression != Compression::BITFIELDS && context.dib.info.compression != Compression::ALPHABITFIELDS) {
streamer.drop_bytes(12);
return true;
}
context.dib.info.masks.append(streamer.read_u32());
context.dib.info.masks.append(streamer.read_u32());
context.dib.info.masks.append(streamer.read_u32());

View file

@ -84,6 +84,16 @@ TEST_CASE(test_bmp_too_many_palette_colors)
TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 2, 2 }));
}
TEST_CASE(test_bmp_v4)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("bmp/2x2x32_v4.bmp"sv)));
EXPECT(Gfx::BMPImageDecoderPlugin::sniff(file->bytes()));
auto plugin_decoder = TRY_OR_FAIL(Gfx::BMPImageDecoderPlugin::create(file->bytes()));
auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 2, 2 }));
EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::Red);
}
TEST_CASE(test_ico_malformed_frame)
{
Array test_inputs = {

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 B