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:
parent
c908c14aac
commit
48ca895f5f
Notes:
github-actions[bot]
2025-05-09 19:49:34 +00:00
Author: https://github.com/aplefull
Commit: 48ca895f5f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4660
Reviewed-by: https://github.com/gmta ✅
3 changed files with 15 additions and 0 deletions
|
@ -724,6 +724,11 @@ static bool decode_bmp_v2_dib(BMPLoadingContext& context, InputStreamer& streame
|
||||||
if (!decode_bmp_info_dib(context, streamer))
|
if (!decode_bmp_info_dib(context, streamer))
|
||||||
return false;
|
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());
|
context.dib.info.masks.append(streamer.read_u32());
|
||||||
context.dib.info.masks.append(streamer.read_u32());
|
context.dib.info.masks.append(streamer.read_u32());
|
||||||
|
|
|
@ -84,6 +84,16 @@ TEST_CASE(test_bmp_too_many_palette_colors)
|
||||||
TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 2, 2 }));
|
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)
|
TEST_CASE(test_ico_malformed_frame)
|
||||||
{
|
{
|
||||||
Array test_inputs = {
|
Array test_inputs = {
|
||||||
|
|
BIN
Tests/LibGfx/test-inputs/bmp/2x2x32_v4.bmp
Normal file
BIN
Tests/LibGfx/test-inputs/bmp/2x2x32_v4.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 138 B |
Loading…
Add table
Add a link
Reference in a new issue