mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:37:45 +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
2 changed files with 10 additions and 1 deletions
|
@ -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
|
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() };
|
FixedMemoryStream stream { buffer.span() };
|
||||||
|
|
||||||
TRY(stream.write_value(size_in_bytes()));
|
TRY(stream.write_value(size_in_bytes()));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue