The vulnerability is an out-of-bounds read in ImageMagick's UIL and XPM image encoders. It occurs when processing images in High Dynamic Range Imaging (HDRI) mode, where pixel quantum values are floating-point numbers. The GetPixelIndex() function can return a negative index value for certain crafted images.
The WriteUILImage function in coders/uil.c and the WriteXPMImage function in coders/xpm.c both use the index returned by GetPixelIndex() to access an array without first validating that the index is non-negative. This leads to a global buffer overflow (out-of-bounds read).
The analysis of the commit c9c87dbaba56bf82aebd3392e11f0ffd93709b12 confirms the vulnerability in WriteUILImage and shows the fix, which is to add a check to ensure the index is not negative.
Although the patch for WriteXPMImage was not provided in the commit details, the vulnerability description and the provided stack trace (READ of size 1 at ... in WriteXPMImage coders/xpm.c:1135) are strong evidence that WriteXPMImage is also vulnerable due to the same underlying issue.
An attacker can exploit this by crafting a malicious image file that, when converted to the UIL or XPM format by a vulnerable version of ImageMagick, will trigger the out-of-bounds read. This can lead to a crash of the application or disclosure of sensitive information from the process memory.
The identified vulnerable functions are the ones that would appear in a profiler or stack trace during the exploitation of this vulnerability.