From 1a998c729b100ac8107b41ec9d3e5d7450e48e99 Mon Sep 17 00:00:00 2001 From: peterhillman Date: Wed, 17 Feb 2021 14:56:17 +1300 Subject: [PATCH] handle reallocation of idmanifest attributes (#925) Signed-off-by: Peter Hillman --- src/lib/OpenEXR/ImfIDManifestAttribute.cpp | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/lib/OpenEXR/ImfIDManifestAttribute.cpp b/src/lib/OpenEXR/ImfIDManifestAttribute.cpp index 5b9cd41bf4..6403234cf9 100644 --- a/src/lib/OpenEXR/ImfIDManifestAttribute.cpp +++ b/src/lib/OpenEXR/ImfIDManifestAttribute.cpp @@ -33,11 +33,30 @@ template <> void IDManifestAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int size, int version) { - int read = 0; - Xdr::read(is,_value._uncompressedDataSize); - _value._data = (unsigned char*) malloc(size-4); + if (size<4) + { + throw IEX_NAMESPACE::InputExc("Invalid size field reading idmanifest attribute"); + } _value._compressedDataSize = size-4; + + if (_value._data) + { + // if attribute is reallocated , free up previous memory + free( static_cast(_value._data) ); + _value._data = nullptr; + } + + + // + // first four bytes: data size once data is uncompressed + // + Xdr::read(is,_value._uncompressedDataSize); + + // + // allocate memory for compressed storage and read data + // + _value._data = static_cast( malloc(size-4) ); char* input = (char*) _value._data; Xdr::read(is,input,_value._compressedDataSize); }