LibGfx: Allow IPC encode/decode of empty BitmapSequence

This would fail with EINVAL earlier, due to an attempt to create a
zero-length Core::AnonymousBuffer.

We fix this by transferring the buffer length separately, and only
going down the AnonymousBuffer allocation path if the length is
non-zero.
This commit is contained in:
Andreas Kling 2024-12-18 08:49:25 +01:00 committed by Andreas Kling
commit f44166ebd0
Notes: github-actions[bot] 2024-12-19 15:50:38 +00:00

View file

@ -76,6 +76,9 @@ ErrorOr<void> encode(Encoder& encoder, Gfx::BitmapSequence const& bitmap_sequenc
TRY(encoder.encode(metadata)); TRY(encoder.encode(metadata));
TRY(encoder.encode(total_buffer_size));
if (total_buffer_size > 0) {
// collate all of the bitmap data into one contiguous buffer // collate all of the bitmap data into one contiguous buffer
auto collated_buffer = TRY(Core::AnonymousBuffer::create_with_size(total_buffer_size)); auto collated_buffer = TRY(Core::AnonymousBuffer::create_with_size(total_buffer_size));
@ -90,6 +93,7 @@ ErrorOr<void> encode(Encoder& encoder, Gfx::BitmapSequence const& bitmap_sequenc
} }
TRY(encoder.encode(collated_buffer)); TRY(encoder.encode(collated_buffer));
}
return {}; return {};
} }
@ -98,7 +102,12 @@ template<>
ErrorOr<Gfx::BitmapSequence> decode(Decoder& decoder) ErrorOr<Gfx::BitmapSequence> decode(Decoder& decoder)
{ {
auto metadata_list = TRY(decoder.decode<Vector<Optional<Gfx::BitmapMetadata>>>()); auto metadata_list = TRY(decoder.decode<Vector<Optional<Gfx::BitmapMetadata>>>());
auto collated_buffer = TRY(decoder.decode<Core::AnonymousBuffer>());
auto total_buffer_size = TRY(decoder.decode<size_t>());
Core::AnonymousBuffer collated_buffer;
if (total_buffer_size > 0)
collated_buffer = TRY(decoder.decode<Core::AnonymousBuffer>());
Gfx::BitmapSequence result = {}; Gfx::BitmapSequence result = {};
auto& bitmaps = result.bitmaps; auto& bitmaps = result.bitmaps;