mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
LibGfx: Validate bit depths, and don't assert on invalid color type
The PNG spec says that each color type only allows certain bit depths, so add explicit checks for that.
This commit is contained in:
parent
fe999d6281
commit
34c5478f31
Notes:
sideshowbarker
2024-07-19 01:10:41 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/34c5478f313 Pull-request: https://github.com/SerenityOS/serenity/pull/4247
1 changed files with 11 additions and 1 deletions
|
@ -847,22 +847,32 @@ static bool process_IHDR(const ByteBuffer& data, PNGLoadingContext& context)
|
|||
|
||||
switch (context.color_type) {
|
||||
case 0: // Each pixel is a grayscale sample.
|
||||
if (context.bit_depth != 1 && context.bit_depth != 2 && context.bit_depth != 4 && context.bit_depth != 8 && context.bit_depth != 16)
|
||||
return false;
|
||||
context.channels = 1;
|
||||
break;
|
||||
case 4: // Each pixel is a grayscale sample, followed by an alpha sample.
|
||||
if (context.bit_depth != 8 && context.bit_depth != 16)
|
||||
return false;
|
||||
context.channels = 2;
|
||||
break;
|
||||
case 2: // Each pixel is an RGB sample
|
||||
if (context.bit_depth != 8 && context.bit_depth != 16)
|
||||
return false;
|
||||
context.channels = 3;
|
||||
break;
|
||||
case 3: // Each pixel is a palette index; a PLTE chunk must appear.
|
||||
if (context.bit_depth != 1 && context.bit_depth != 2 && context.bit_depth != 4 && context.bit_depth != 8)
|
||||
return false;
|
||||
context.channels = 1;
|
||||
break;
|
||||
case 6: // Each pixel is an RGB sample, followed by an alpha sample.
|
||||
if (context.bit_depth != 8 && context.bit_depth != 16)
|
||||
return false;
|
||||
context.channels = 4;
|
||||
break;
|
||||
default:
|
||||
ASSERT_NOT_REACHED();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue