From 7c1df68be314793fd915d63d930f81351d723f0b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 16 Jan 2021 10:58:02 +0100 Subject: [PATCH] LibGfx: Don't encode invalid Gfx::ShareableBitmap as IPC::File IPC::File should only be used when there's an actual file to pass. Invalid ShareableBitmaps don't have a backing file, so fix this by first encoding a "valid" flag. --- Userland/Libraries/LibGfx/ShareableBitmap.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Userland/Libraries/LibGfx/ShareableBitmap.cpp b/Userland/Libraries/LibGfx/ShareableBitmap.cpp index 6cfa44a4b0..c3468445fc 100644 --- a/Userland/Libraries/LibGfx/ShareableBitmap.cpp +++ b/Userland/Libraries/LibGfx/ShareableBitmap.cpp @@ -44,6 +44,9 @@ namespace IPC { bool encode(Encoder& encoder, const Gfx::ShareableBitmap& shareable_bitmap) { + encoder << shareable_bitmap.is_valid(); + if (!shareable_bitmap.is_valid()) + return true; encoder << IPC::File(shareable_bitmap.anon_fd()); encoder << shareable_bitmap.width(); encoder << shareable_bitmap.height(); @@ -52,6 +55,13 @@ bool encode(Encoder& encoder, const Gfx::ShareableBitmap& shareable_bitmap) bool decode(Decoder& decoder, Gfx::ShareableBitmap& shareable_bitmap) { + bool valid = false; + if (!decoder.decode(valid)) + return false; + if (!valid) { + shareable_bitmap = {}; + return true; + } IPC::File anon_file; Gfx::IntSize size; if (!decoder.decode(anon_file))