From e3032d421cadb221f3d431d31f86ce661be9c3e9 Mon Sep 17 00:00:00 2001 From: Kimball Thurston Date: Sun, 11 Feb 2024 22:50:44 +1300 Subject: [PATCH] check and control reduceMemory and reduceTime in stream mode (#1635) exrcheck by default uses file mode, but the fuzzer and exrcheck -s use stream mode, need to respect the memory and time flags consistently on that path as well. Will address OSS-Fuzz 66612, although real fix underlying is in #1634 Signed-off-by: Kimball Thurston --- src/lib/OpenEXRUtil/ImfCheckFile.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lib/OpenEXRUtil/ImfCheckFile.cpp b/src/lib/OpenEXRUtil/ImfCheckFile.cpp index 202ca0d2d0..ca28cd6d0d 100644 --- a/src/lib/OpenEXRUtil/ImfCheckFile.cpp +++ b/src/lib/OpenEXRUtil/ImfCheckFile.cpp @@ -1260,7 +1260,11 @@ realloc_deepdata(exr_decode_pipeline_t* decode) } if (ud->size () < bytes) + { ud->resize (bytes); + if (ud->capacity() < bytes) + return EXR_ERR_OUT_OF_MEMORY; + } uint8_t* dptr = &((*ud)[0]); for (int c = 0; c < decode->channel_count; c++) @@ -1730,6 +1734,19 @@ runCoreChecks ( cinit.read_fn = &memstream_read; cinit.size_fn = &memstream_size; cinit.error_handler_fn = &core_error_handler_cb; + if (reduceMemory || reduceTime) + { + /* could use set_default functions for this, but those just + * initialize the context, doing it in the initializer is mt + * safe... + * exr_set_default_maximum_image_size (2048, 2048); + * exr_set_default_maximum_tile_size (512, 512); + */ + cinit.max_image_width = 2048; + cinit.max_image_height = 2048; + cinit.max_tile_width = 512; + cinit.max_tile_height = 512; + } rv = exr_start_read (&f, "", &cinit); if (rv != EXR_ERR_SUCCESS) return true;