Description
Version: ImageMagick 7.0.6-1 Q16 x86_64
#./magick identify $FILE
When identify MIFF file , imagemagick will allocate memory to store the data, here is the critical code:
(Miff.c , in function ReadMIFFImage)
status=AcquireImageColormap(image,colors != 0 ? colors : 256,exception); //1161
The "colors" can be obtained from local value "options" as follow, and the options is controlled by image , in other words the “colors" can be read from input file.
colors=StringToUnsignedLong(options); //686
The function StringToUnsignedLong convert string to unsigned long type, but the return value was not checked.
Here is my policy.xml to limit memory usage,but 256MB limit can be bypassed.
...
<policy domain="resource" name="area" value="100MP"/>
<policy domain="resource" name="memory" value="256MiB”/>
...
testcase: https://github.com/bestshow/p0cs/blob/master/memory_exhaustion_in_ReadMIFFImage
Credit ADLab of Venustech