1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:44:58 +00:00

Userland: Return empty if ImageDecoder client receives an invalid frame

This simplifies error checking for all the users of the ImageDecoder
client.
This commit is contained in:
Tim Ledbetter 2023-10-01 19:56:19 +01:00 committed by Andreas Kling
parent e6c1429311
commit eaa6304aab
6 changed files with 11 additions and 15 deletions

View file

@ -48,12 +48,13 @@ Optional<DecodedImage> Client::decode_image(ReadonlyBytes encoded_data, Optional
DecodedImage image;
image.is_animated = response.is_animated();
image.loop_count = response.loop_count();
image.frames.resize(response.bitmaps().size());
image.frames.ensure_capacity(response.bitmaps().size());
auto bitmaps = response.take_bitmaps();
for (size_t i = 0; i < image.frames.size(); ++i) {
auto& frame = image.frames[i];
frame.bitmap = bitmaps[i].bitmap();
frame.duration = response.durations()[i];
for (size_t i = 0; i < bitmaps.size(); ++i) {
if (!bitmaps[i].is_valid())
return {};
image.frames.empend(*bitmaps[i].bitmap(), response.durations()[i]);
}
return image;
}

View file

@ -14,7 +14,7 @@
namespace ImageDecoderClient {
struct Frame {
RefPtr<Gfx::Bitmap> bitmap;
NonnullRefPtr<Gfx::Bitmap> bitmap;
u32 duration { 0 };
};