1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

LibGfx/PNG: Make invalid sRGB chunk size non-fatal

https://www.haiku-os.org/images/bg-page.png has a size of 0 for
example.

Just ignoring the chunk instead of assuming that the image is sRGB
and has Perceptual rendering intent matches what libpng does
(cf `png_handle_sRGB()`), so let's do that too.

(All other chunk handlers are still strict about size.)
This commit is contained in:
Nico Weber 2023-07-11 08:52:41 -04:00 committed by Andreas Kling
parent 3b2a7135b2
commit f7f9f1f47f

View file

@ -1104,8 +1104,11 @@ static ErrorOr<void> process_gAMA(ReadonlyBytes data, PNGLoadingContext& context
static ErrorOr<void> process_sRGB(ReadonlyBytes data, PNGLoadingContext& context)
{
// https://www.w3.org/TR/png/#srgb-standard-colour-space
if (data.size() != 1)
return Error::from_string_literal("sRGB chunk has an abnormal size");
if (data.size() != 1) {
// Invalid per spec, but (rarely) happens in the wild. Log and ignore.
warnln("warning: PNG sRGB chunk has an abnormal size; ignoring");
return {};
}
u8 rendering_intent = data[0];
if (rendering_intent > 3)