1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:47:35 +00:00

LibPDF: Make prediction filters error on user-controlled alloc OOM

This commit is contained in:
Nico Weber 2024-01-15 22:01:40 -05:00 committed by Andrew Kaster
parent 93f5420282
commit 9f9dbb325b

View file

@ -155,7 +155,7 @@ PDFErrorOr<ByteBuffer> Filter::decode_png_prediction(Bytes bytes, size_t bytes_p
int number_of_rows = bytes.size() / bytes_per_row; int number_of_rows = bytes.size() / bytes_per_row;
ByteBuffer decoded; 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 empty_row = TRY(ByteBuffer::create_zeroed(bytes_per_row - 1));
auto previous_row = empty_row.bytes(); auto previous_row = empty_row.bytes();
@ -210,7 +210,7 @@ PDFErrorOr<ByteBuffer> Filter::decode_tiff_prediction(Bytes bytes, int columns,
int samples_per_pixel = colors; int samples_per_pixel = colors;
ByteBuffer decoded; ByteBuffer decoded;
decoded.ensure_capacity(bytes.size()); TRY(decoded.try_ensure_capacity(bytes.size()));
while (!bytes.is_empty()) { while (!bytes.is_empty()) {
auto row = bytes.slice(0, columns * samples_per_pixel); auto row = bytes.slice(0, columns * samples_per_pixel);