Skip to content

Commit

Permalink
handle reallocation of idmanifest attributes (#925)
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>
  • Loading branch information
peterhillman authored Feb 17, 2021
1 parent 01be8a1 commit 1a998c7
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/lib/OpenEXR/ImfIDManifestAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,30 @@ template <>
void
IDManifestAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int size, int version)
{
int read = 0;

Xdr::read<StreamIO>(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<void*>(_value._data) );
_value._data = nullptr;
}


//
// first four bytes: data size once data is uncompressed
//
Xdr::read<StreamIO>(is,_value._uncompressedDataSize);

//
// allocate memory for compressed storage and read data
//
_value._data = static_cast<unsigned char*>( malloc(size-4) );
char* input = (char*) _value._data;
Xdr::read<StreamIO>(is,input,_value._compressedDataSize);
}
Expand Down

0 comments on commit 1a998c7

Please sign in to comment.