mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 01:00:05 +00:00
LibGfx: Clamp BMP color palette to 1024
Other browsers don't think that BMP files with more than 1024 colors are invalid. They clamp the palette instead, and now we do the same. This allows us to load more BMPs.
This commit is contained in:
parent
70b52e0994
commit
c908c14aac
Notes:
github-actions[bot]
2025-05-09 19:49:41 +00:00
Author: https://github.com/aplefull
Commit: c908c14aac
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4660
Reviewed-by: https://github.com/gmta ✅
3 changed files with 13 additions and 8 deletions
|
@ -655,10 +655,8 @@ static bool decode_bmp_osv2_dib(BMPLoadingContext& context, InputStreamer& strea
|
|||
return false;
|
||||
}
|
||||
|
||||
if (info.number_of_palette_colors > color_palette_limit || info.number_of_important_palette_colors > color_palette_limit) {
|
||||
dbgln("BMP header indicates too many palette colors: {}", info.number_of_palette_colors);
|
||||
return false;
|
||||
}
|
||||
info.number_of_palette_colors = min(info.number_of_palette_colors, color_palette_limit);
|
||||
info.number_of_important_palette_colors = min(info.number_of_important_palette_colors, color_palette_limit);
|
||||
|
||||
// Units (2) + reserved (2)
|
||||
streamer.drop_bytes(4);
|
||||
|
@ -703,10 +701,8 @@ static bool decode_bmp_info_dib(BMPLoadingContext& context, InputStreamer& strea
|
|||
info.number_of_palette_colors = streamer.read_u32();
|
||||
info.number_of_important_palette_colors = streamer.read_u32();
|
||||
|
||||
if (info.number_of_palette_colors > color_palette_limit || info.number_of_important_palette_colors > color_palette_limit) {
|
||||
dbgln("BMP header indicates too many palette colors: {}", info.number_of_palette_colors);
|
||||
return false;
|
||||
}
|
||||
info.number_of_palette_colors = min(info.number_of_palette_colors, color_palette_limit);
|
||||
info.number_of_important_palette_colors = min(info.number_of_important_palette_colors, color_palette_limit);
|
||||
|
||||
if (info.number_of_important_palette_colors == 0)
|
||||
info.number_of_important_palette_colors = info.number_of_palette_colors;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue