Here is the critical code:
...
sun_data=MagickAllocateMemory(unsigned char *,sun_data_length);//562
if (sun_data == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image);
if ((count=ReadBlob(image,sun_data_length,(char *) sun_data))
!= sun_data_length)
{
MagickFreeMemory(sun_data);
ThrowReaderException(CorruptImageError,UnableToReadImageData,image);
}
sun_pixels=sun_data;
if (sun_info.type == RT_ENCODED)
{
/*
Read run-length encoded raster pixels (padded to 16-bit boundary).
*/
sun_pixels=MagickAllocateMemory(unsigned char *,bytes_per_image);
if (sun_pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,
image);//580
status &= DecodeImage(sun_data,sun_data_length,sun_pixels,bytes_per_image);
MagickFreeMemory(sun_data);
if (status != MagickPass)
{
MagickFreeMemory(sun_pixels);
ThrowReaderException(CorruptImageError,UnableToRunlengthDecodeImage,image);
}
}
...
Line 580 do not free memory about sun_data, this will cause memory leak.
Credit: ADLab of Venustech
This problem is fixed by Mercurial changeset 15190:40c1b7f74052. Thanks for the report!