1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:37:35 +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

@ -44,7 +44,11 @@ Optional<ByteBuffer> Filter::decode_ascii_hex(ReadonlyBytes const& bytes)
// FIXME: Integrate this padding into AK/Hex?
auto output = ByteBuffer::create_zeroed(bytes.size() / 2 + 1);
auto output_result = ByteBuffer::create_zeroed(bytes.size() / 2 + 1);
if (!output_result.has_value())
return output_result;
auto output = output_result.release_value();
for (size_t i = 0; i < bytes.size() / 2; ++i) {
const auto c1 = decode_hex_digit(static_cast<char>(bytes[i * 2]));
@ -61,7 +65,7 @@ Optional<ByteBuffer> Filter::decode_ascii_hex(ReadonlyBytes const& bytes)
// Process last byte with a padded zero
output[output.size() - 1] = decode_hex_digit(static_cast<char>(bytes[bytes.size() - 1])) * 16;
return output;
return { move(output) };
};
Optional<ByteBuffer> Filter::decode_ascii85(ReadonlyBytes const& bytes)

View file

@ -262,7 +262,10 @@ bool Parser::initialize_hint_tables()
auto overflow_size = overflow_hint_stream->bytes().size();
auto total_size = primary_size + overflow_size;
possible_merged_stream_buffer = ByteBuffer::create_uninitialized(total_size);
auto buffer_result = ByteBuffer::create_uninitialized(total_size);
if (!buffer_result.has_value())
return false;
possible_merged_stream_buffer = buffer_result.release_value();
auto ok = possible_merged_stream_buffer.try_append(primary_hint_stream->bytes());
ok = ok && possible_merged_stream_buffer.try_append(overflow_hint_stream->bytes());
if (!ok)