mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
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:
parent
6737b8b065
commit
f44166ebd0
Notes:
github-actions[bot]
2024-12-19 15:50:38 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/f44166ebd01 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2961 Reviewed-by: https://github.com/gmta ✅
1 changed files with 21 additions and 12 deletions
|
@ -76,20 +76,24 @@ ErrorOr<void> encode(Encoder& encoder, Gfx::BitmapSequence const& bitmap_sequenc
|
|||
|
||||
TRY(encoder.encode(metadata));
|
||||
|
||||
// collate all of the bitmap data into one contiguous buffer
|
||||
auto collated_buffer = TRY(Core::AnonymousBuffer::create_with_size(total_buffer_size));
|
||||
TRY(encoder.encode(total_buffer_size));
|
||||
|
||||
Bytes buffer_bytes = { collated_buffer.data<u8>(), collated_buffer.size() };
|
||||
size_t write_offset = 0;
|
||||
for (auto const& bitmap_option : bitmaps) {
|
||||
if (bitmap_option.has_value()) {
|
||||
auto const& bitmap = bitmap_option.value();
|
||||
buffer_bytes.overwrite(write_offset, bitmap->scanline(0), bitmap->size_in_bytes());
|
||||
write_offset += bitmap->size_in_bytes();
|
||||
if (total_buffer_size > 0) {
|
||||
// collate all of the bitmap data into one contiguous buffer
|
||||
auto collated_buffer = TRY(Core::AnonymousBuffer::create_with_size(total_buffer_size));
|
||||
|
||||
Bytes buffer_bytes = { collated_buffer.data<u8>(), collated_buffer.size() };
|
||||
size_t write_offset = 0;
|
||||
for (auto const& bitmap_option : bitmaps) {
|
||||
if (bitmap_option.has_value()) {
|
||||
auto const& bitmap = bitmap_option.value();
|
||||
buffer_bytes.overwrite(write_offset, bitmap->scanline(0), bitmap->size_in_bytes());
|
||||
write_offset += bitmap->size_in_bytes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TRY(encoder.encode(collated_buffer));
|
||||
TRY(encoder.encode(collated_buffer));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -98,7 +102,12 @@ template<>
|
|||
ErrorOr<Gfx::BitmapSequence> decode(Decoder& decoder)
|
||||
{
|
||||
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 = {};
|
||||
auto& bitmaps = result.bitmaps;
|
||||
|
|
Loading…
Reference in a new issue