summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibPDF
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-09-06 03:29:52 +0430
committerAndreas Kling <kling@serenityos.org>2021-09-06 01:53:26 +0200
commit97e97bccab085823d1365cb54142fd8c41dbcd8c (patch)
tree9008687dbcdfb6f36f6dc6372aa382b15b9d36c8 /Userland/Libraries/LibPDF
parent3a9f00c59bad7735970c72cb940d08161fda09b0 (diff)
downloadserenity-97e97bccab085823d1365cb54142fd8c41dbcd8c.zip
Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe
Diffstat (limited to 'Userland/Libraries/LibPDF')
-rw-r--r--Userland/Libraries/LibPDF/Filter.cpp8
-rw-r--r--Userland/Libraries/LibPDF/Parser.cpp5
2 files changed, 10 insertions, 3 deletions
diff --git a/Userland/Libraries/LibPDF/Filter.cpp b/Userland/Libraries/LibPDF/Filter.cpp
index bdb8b10b82..597aa6d116 100644
--- a/Userland/Libraries/LibPDF/Filter.cpp
+++ b/Userland/Libraries/LibPDF/Filter.cpp
@@ -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)
diff --git a/Userland/Libraries/LibPDF/Parser.cpp b/Userland/Libraries/LibPDF/Parser.cpp
index b676e31ed8..d553589466 100644
--- a/Userland/Libraries/LibPDF/Parser.cpp
+++ b/Userland/Libraries/LibPDF/Parser.cpp
@@ -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)