mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 11:36:10 +00:00
LibGfx: Reject PNG files with invalid filter/interlace methods
Might as well reject these when parsing the IHDR chunk instead of continuing to load something invalid.
This commit is contained in:
parent
5f182746b6
commit
068615fe5e
Notes:
sideshowbarker
2024-07-19 00:39:29 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/068615fe5e2
1 changed files with 20 additions and 0 deletions
|
@ -818,6 +818,16 @@ static RefPtr<Gfx::Bitmap> load_png_impl(const u8* data, size_t data_size)
|
|||
return context.bitmap;
|
||||
}
|
||||
|
||||
static bool is_valid_compression_method(u8 compression_method)
|
||||
{
|
||||
return compression_method == 0;
|
||||
}
|
||||
|
||||
static bool is_valid_filter_method(u8 filter_method)
|
||||
{
|
||||
return filter_method <= 4;
|
||||
}
|
||||
|
||||
static bool process_IHDR(ReadonlyBytes data, PNGLoadingContext& context)
|
||||
{
|
||||
if (data.size() < (int)sizeof(PNG_IHDR))
|
||||
|
@ -829,6 +839,16 @@ static bool process_IHDR(ReadonlyBytes data, PNGLoadingContext& context)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!is_valid_compression_method(ihdr.compression_method)) {
|
||||
dbgln("PNG has invalid compression method {}", ihdr.compression_method);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_valid_filter_method(ihdr.filter_method)) {
|
||||
dbgln("PNG has invalid filter method {}", ihdr.filter_method);
|
||||
return false;
|
||||
}
|
||||
|
||||
context.width = ihdr.width;
|
||||
context.height = ihdr.height;
|
||||
context.bit_depth = ihdr.bit_depth;
|
||||
|
|
Loading…
Add table
Reference in a new issue