Skip to content

Commit

Permalink
LibGfx/WebPLoader: Survive calling loop_count() before other accessors
Browse files Browse the repository at this point in the history
Fixes `animation` asserting when reading a webp input.

(The other order of operations is still covered by TestImageWriter.cpp.)
  • Loading branch information
nico committed Jun 3, 2024
1 parent 1e4a78e commit de1318d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Tests/LibGfx/TestImageDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
5 changes: 5 additions & 0 deletions Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit de1318d

Please sign in to comment.