From da42c1552c9306022b14ecb86ff041a69d828be9 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 29 Nov 2021 13:10:07 +0100 Subject: [PATCH] ImageDecoder: Fix assertion after failed decode We were calling value() on an ErrorOr containing an error when trying to extract the frame duration after a failed decode. This fixes ImageDecoder crashing on various websites. --- Userland/Services/ImageDecoder/ClientConnection.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Userland/Services/ImageDecoder/ClientConnection.cpp b/Userland/Services/ImageDecoder/ClientConnection.cpp index d180433380..2522d7bba1 100644 --- a/Userland/Services/ImageDecoder/ClientConnection.cpp +++ b/Userland/Services/ImageDecoder/ClientConnection.cpp @@ -53,11 +53,14 @@ Messages::ImageDecoderServer::DecodeImageResponse ClientConnection::decode_image Vector durations; for (size_t i = 0; i < decoder->frame_count(); ++i) { auto frame_or_error = decoder->frame(i); - if (frame_or_error.is_error() || !frame_or_error.value().image) + if (frame_or_error.is_error()) { bitmaps.append(Gfx::ShareableBitmap {}); - else - bitmaps.append(frame_or_error.value().image->to_shareable_bitmap()); - durations.append(frame_or_error.value().duration); + durations.append(0); + } else { + auto frame = frame_or_error.release_value(); + bitmaps.append(frame.image->to_shareable_bitmap()); + durations.append(frame.duration); + } } return { decoder->is_animated(), static_cast(decoder->loop_count()), bitmaps, durations };