// back

Multiple Vendor ImageMagick Off-By-One Vulnerability



ImageMagick is a suite of image manipulation tools (animate, composite, conjure, convert, display, identify, import, mogrify and montage) that are sometimes used by other applications for processing image files. For more information about ImageMagick, visit the vendor's site at the following URL.



Remote exploitation of an off-by-one vulnerability in ImageMagick, as included in various vendors' operating system distributions, allows attackers to execute arbitrary code.

This vulnerability specifically exists in the ReadBlobString() function in magick/blob.c as shown below.

 3110 for (i=0; i < (long) maxtextextent; i++) 3111 { 3112 p=readblobstream(image,1,buffer,&count); ... 3119 string[i]=(char) (*p); 3120 if ((string[i] == ' ') || (string[i] == ' ')) 3121 break; 3122 } 3123 string[i]=''; 

The variable "string" is a character array of length "MaxTextExtent". An off-by-one buffer overflow will occur on line 3123 when "i" is exactly "MaxTextExtent". This function is called from several image file processing routines. Most of the buffers involved are stack based, although some are on the heap.


Exploitation of this vulnerability allows an attacker to execute arbitrary code in the context of the user.

One way of exploiting this vulnerability is to persuade a targeted user to open a malicious image file with a program that utilizes the ImageMagick library.

As the tools that are part of ImageMagick are sometimes used as helper tools by other applications, this user may be the same as the web server user. This scenario is somewhat more severe than the previously described attack vector since the image processing can occur automatically.

Exploitation in stack-based scenarios depends on the stack layout, which depends on the compiler and compiler options used to build the library.


iDefense Labs confirmed that ImageMagick version 6.3.4 is vulnerable. It is suspected that other versions of ImageMagick are also vulnerable.


iDefense is unaware of any effective workaround for this vulnerability.


The ImageMagick maintainers have addressed this vulnerability with the release of version 6.3.5-9. More information is available from the following URL.



The Common Vulnerabilities and Exposures (CVE) project has assigned the name CVE-2007-4987 to this issue. This is a candidate for inclusion in the CVE list (http://cve.mitre.org/), which standardizes names for security problems.


09/04/2007 Initial vendor notification
09/05/2007 Initial vendor response
09/19/2007 Coordinated public disclosure


This vulnerability was reported to iDefense by regenrecht.

Get paid for vulnerability research

Free tools, research and upcoming events


Copyright © 2007 Verisign, Inc.

Permission is granted for the redistribution of this alert electronically. It may not be edited in any way without the express written consent of iDefense. If you wish to reprint the whole or any part of this alert in any other medium other than electronically, please e-mail customer service for permission.

Disclaimer: The information in the advisory is believed to be accurate at the time of publishing based on currently available information. Use of the information constitutes acceptance for use in an AS IS condition. There are no warranties with regard to this information. Neither the author nor the publisher accepts any liability for any direct, indirect, or consequential loss or damage arising from use of, or reliance on, this information.