From 99d280a9276b4f310a4374b0a06a9bac8f6ba495 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 27 May 2024 20:30:08 -0400 Subject: [PATCH] LibGfx/WebPLoader: Relax vp8x / vp8l alpha check The check from 0805319d1e6a8 is too strict for animated images: It's possible that an animation has alpha, but a frame doesn't. (For example, if the animation is 10x10 pixels, but one frame updates just 1x1 pixels. But even a full-sized frame could just not have alpha.) If the VP8X header claims that the animation has alpha, we could check that at least one frame has alpha, but for now we just don't do any checking for animated images. --- Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp index 2d0b23f238a..c4c00b4e291 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp @@ -518,7 +518,9 @@ static ErrorOr> decode_webp_image_data(WebPLoadingContext& VERIFY(!image_data.alpha_chunk.has_value()); auto vp8l_header = TRY(decode_webp_chunk_VP8L_header(image_data.image_data_chunk.data())); - if (context.first_chunk->id() == "VP8X" && context.vp8x_header.has_alpha != vp8l_header.is_alpha_used) + // Check that the VP8X header alpha flag matches the VP8L header alpha flag. + // FIXME: For animated images, if VP8X has alpha then at least one frame should have alpha. But we currently don't check this for animations. + if (context.first_chunk->id() == "VP8X" && !context.animation_frame_chunks_data.has_value() && context.vp8x_header.has_alpha != vp8l_header.is_alpha_used) return Error::from_string_literal("WebPImageDecoderPlugin: VP8X header alpha flag doesn't match VP8L header"); return decode_webp_chunk_VP8L_contents(vp8l_header);