1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:37:34 +00:00

Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe

This commit is contained in:
Ali Mohammad Pur 2021-09-06 03:29:52 +04:30 committed by Andreas Kling
parent 3a9f00c59b
commit 97e97bccab
105 changed files with 629 additions and 290 deletions

View file

@ -45,7 +45,11 @@ private:
static ByteBuffer write_pixel_data(const RefPtr<Bitmap> bitmap, int pixel_row_data_size, int bytes_per_pixel, bool include_alpha_channel)
{
int image_size = pixel_row_data_size * bitmap->height();
auto buffer = ByteBuffer::create_uninitialized(image_size);
auto buffer_result = ByteBuffer::create_uninitialized(image_size);
if (!buffer_result.has_value())
return {};
auto buffer = buffer_result.release_value();
int current_row = 0;
for (int y = bitmap->physical_height() - 1; y >= 0; --y) {
@ -95,7 +99,11 @@ ByteBuffer BMPWriter::dump(const RefPtr<Bitmap> bitmap, DibHeader dib_header)
int pixel_row_data_size = (m_bytes_per_pixel * 8 * bitmap->width() + 31) / 32 * 4;
int image_size = pixel_row_data_size * bitmap->height();
auto buffer = ByteBuffer::create_uninitialized(pixel_data_offset);
auto buffer_result = ByteBuffer::create_uninitialized(pixel_data_offset);
if (!buffer_result.has_value())
return {};
auto buffer = buffer_result.release_value();
auto pixel_data = write_pixel_data(bitmap, pixel_row_data_size, m_bytes_per_pixel, m_include_alpha_channel);
pixel_data = compress_pixel_data(pixel_data, m_compression);