mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 16:21:29 +00:00
LibGfx: Fix serializing Gfx::Bitmaps
a396bb0
removed the palette field but did not update the allocation size
in `Bitmap::serialize_to_byte_buffer()`. This led to a few crashes (I
noticed this from a drag/drop crash in the file manager).
Fixes #21434
This commit is contained in:
parent
f0cd7adaf8
commit
95bf6ddb8e
Notes:
sideshowbarker
2024-07-17 18:38:54 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/95bf6ddb8e Pull-request: https://github.com/SerenityOS/serenity/pull/21456 Issue: https://github.com/SerenityOS/serenity/issues/21434
|
@ -126,3 +126,12 @@ TEST_CASE(0008_bitmap_downscaling_height1)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(0009_serialize_and_deserialize_roundtrip)
|
||||
{
|
||||
auto original_bitmap = MUST(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, Gfx::IntSize { 10, 10 }));
|
||||
original_bitmap->fill(Gfx::Color::Red);
|
||||
auto bytes = MUST(original_bitmap->serialize_to_byte_buffer());
|
||||
auto bitmap = MUST(Gfx::Bitmap::create_from_serialized_bytes(bytes));
|
||||
EXPECT(bitmap->visually_equals(original_bitmap));
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::create_from_serialized_bytes(ReadonlyByte
|
|||
|
||||
ErrorOr<ByteBuffer> Bitmap::serialize_to_byte_buffer() const
|
||||
{
|
||||
auto buffer = TRY(ByteBuffer::create_uninitialized(sizeof(size_t) + 4 * sizeof(unsigned) + sizeof(BitmapFormat) + size_in_bytes()));
|
||||
auto buffer = TRY(ByteBuffer::create_uninitialized(sizeof(size_t) + 3 * sizeof(unsigned) + sizeof(BitmapFormat) + size_in_bytes()));
|
||||
FixedMemoryStream stream { buffer.span() };
|
||||
|
||||
TRY(stream.write_value(size_in_bytes()));
|
||||
|
|
Loading…
Reference in a new issue