From 857750dfed145ababc106f650165cd231c240e66 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 2 Jun 2024 20:02:16 -0400 Subject: [PATCH] LibGfx/WebPLoader: Survive calling loop_count() before other accessors Fixes `animation` asserting when reading a webp input. (The other order of operations is still covered by TestImageWriter.cpp.) --- Tests/LibGfx/TestImageDecoder.cpp | 2 +- Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index b29746fe8c0..911f675899d 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -1381,9 +1381,9 @@ TEST_CASE(test_webp_extended_lossless_animated) EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + EXPECT_EQ(plugin_decoder->loop_count(), 42u); EXPECT_EQ(plugin_decoder->frame_count(), 8u); EXPECT(plugin_decoder->is_animated()); - EXPECT_EQ(plugin_decoder->loop_count(), 42u); EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(990, 1050)); diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp index 361fdddd005..d618f22a1b4 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp @@ -639,6 +639,11 @@ size_t WebPImageDecoderPlugin::loop_count() if (!is_animated()) return 0; + if (m_context->state < WebPLoadingContext::State::ChunksDecoded) { + if (set_error(decode_webp_chunks(*m_context))) + return 0; + } + if (m_context->state < WebPLoadingContext::State::AnimationFrameChunksDecoded) { if (set_error(decode_webp_animation_frame_chunks(*m_context))) return 0;