From 9f9dbb325beb0afe02572ba3281ba00229a46fdd Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 15 Jan 2024 22:01:40 -0500 Subject: [PATCH] LibPDF: Make prediction filters error on user-controlled alloc OOM --- Userland/Libraries/LibPDF/Filter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibPDF/Filter.cpp b/Userland/Libraries/LibPDF/Filter.cpp index 2569c67035..4d8f089601 100644 --- a/Userland/Libraries/LibPDF/Filter.cpp +++ b/Userland/Libraries/LibPDF/Filter.cpp @@ -155,7 +155,7 @@ PDFErrorOr Filter::decode_png_prediction(Bytes bytes, size_t bytes_p int number_of_rows = bytes.size() / bytes_per_row; ByteBuffer decoded; - decoded.ensure_capacity(bytes.size() - number_of_rows); + TRY(decoded.try_ensure_capacity(bytes.size() - number_of_rows)); auto empty_row = TRY(ByteBuffer::create_zeroed(bytes_per_row - 1)); auto previous_row = empty_row.bytes(); @@ -210,7 +210,7 @@ PDFErrorOr Filter::decode_tiff_prediction(Bytes bytes, int columns, int samples_per_pixel = colors; ByteBuffer decoded; - decoded.ensure_capacity(bytes.size()); + TRY(decoded.try_ensure_capacity(bytes.size())); while (!bytes.is_empty()) { auto row = bytes.slice(0, columns * samples_per_pixel);