Bug 64839 (CVE-2005-0005) - VUL-0: CVE-2005-0005: ImageMagick heap overflow
Summary: VUL-0: CVE-2005-0005: ImageMagick heap overflow
Status: RESOLVED FIXED
Alias: CVE-2005-0005
Product: SUSE Security Incidents
Classification: Novell Products
Component: Incidents (show other bugs)
Version: unspecified
Hardware: All Linux
: P3 - Medium : Major
Target Milestone: ---
Assignee: Security Team bot
QA Contact: Security Team bot
URL:
Whiteboard: CVSSv2:NVD:CVE-2005-0005:7.5:(AV:N/A...
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-14 17:47 UTC by Ludwig Nussel
Modified: 2021-10-27 11:47 UTC (History)
2 users (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
mainstream patch (1.18 KB, text/x-diff)
2005-01-18 18:31 UTC, Vladimir Nadvornik
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ludwig Nussel 2005-01-14 17:47:13 UTC
We received the following report via vendor-sec.
This issue is not public yet, please keep any information about it inside SUSE.

Date: Thu, 13 Jan 2005 17:31:56 -0500
From: vendor-disclosure <vendor-disclosure@idefense.com>
To: vendor-sec@lst.de
Cc: vendor-disclosure <vendor-disclosure@idefense.com>
Subject: [vendor-sec] iDEFENSE Security Advisory [IDEF0745] Multiple Unix/Linux Vendor ImageMagick .psd Image File Decode Heap Overflow Vulnerability

The attached advisory will be released tomorrow. Please note the Vendor
Response section of the advisory:

   VI. VENDOR RESPONSE

   Multiple unsuccessful attempts were made to inform ImageMagick.org
about this vulnerability.

As a result, a vendor patch is not available for this issue.

Michael Sutton
Director, iDEFENSE Labs


Content-Description: pub_Multiple Unix Linux Vendor ImageMagick .psd Image File Decode Heap Overflow Vulnerability.TXT
Multiple Unix/Linux Vendor ImageMagick .psd Image File Decode Heap
Overflow Vulnerability

iDEFENSE Security Advisory 01.13.05
http://www.idefense.com/application/poi/display?type=vulnerabilities
January 13, 2005

I. BACKGROUND

ImageMagick provides a variety of graphics image-handling libraries and 
capabilities. These libraries are widely used and are shipped by default 
on most Unix and Linux distributions. These libraries are commonly 
installed by default and on computers where any other graphical image 
viewer or X Desktop environment is installed (such as Gnome or KDE).

More information is available at the following site:

   http://www.imagemagick.org

II. DESCRIPTION

Remote exploitation of a buffer overflow vulnerability in The 
ImageMagick's Project's ImageMagick PSD image-decoding module could 
allow an attacker to execute arbitrary code. 

A heap overflow exists within ImageMagick, specifically in the decoding 
of Photoshop Document (PSD) files. The vulnerable code follows:

ImageMagick-6.1.0/coders/psd.c

for (j=0; j < (long) layer_info[i].channels; j++) 
{ 
  layer_info[i].channel_info[j].type=(short)ReadBlobMSBShort(image);
  layer_info[i].channel_info[j].size=ReadBlobMSBLong(image);
  [...]
} 

The array channel_info is only 24 elements large, and the loop variable, 
"j", is bounded by a user-supplied value from the image file, thus 
allowing a heap overflow to occur when more than 24 layers are 
specified. If heap structures are overflowed in a controlled way, 
execution of arbitrary code is possible.

III. ANALYSIS

Exploitation may allow attackers to run arbitrary code on a victim's 
computer if the victim opens a specially formatted image. Such images 
could be delivered by e-mail or HTML, in some cases, and would likely 
not raise suspicion on the victim's part. Exploitation is also possible 
when a web-based application uses ImageMagick to process user-uploaded 
image files.

IV. DETECTION

iDEFENSE has confirmed this vulnerability in ImageMagick 6.1.0 and 
ImageMagick 6.1.7. Earlier versions are also suspected vulnerable.

The following vendors may include susceptible ImageMagick packages: 
	
   The Debian Project 
   MandrakeSoft 
   Red Hat, Inc. 

V. WORKAROUND

Do not open files from untrusted sources. Do not allow untrusted sources 
to process images using your web application.

VI. VENDOR RESPONSE

Multiple unsuccessful attempts were made to inform ImageMagick.org about
this vulnerability.

VII. CVE INFORMATION

A Mitre Corp. Common Vulnerabilities and Exposures (CVE) number has not
been assigned yet.

VIII. DISCLOSURE TIMELINE

12/21/2004  Initial vendor notification
12/22/2004  Rejection notification received from the Magick-bugs mailing
            list
01/13/2005  Public disclosure

IX. CREDIT

Andrei Nigmatulin is credited with this discovery.

Get paid for vulnerability research
http://www.idefense.com/poi/teams/vcp.jsp

X. LEGAL NOTICES

Copyright ? 2004 iDEFENSE, 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
email customerservice@idefense.com 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.
Comment 1 Ludwig Nussel 2005-01-14 20:45:18 UTC
* This comment was added by mail.
Date: Fri, 14 Jan 2005 11:39:15 +0100
From: Martin Schulze <joey@infodrom.org>
To: Free Software Distribution Vendors <vendor-sec@lst.de>
Subject: [vendor-sec] Re: iDEFENSE Security Advisory [IDEF0745] Multiple Unix/Linux Vendor ImageMagick .psd Image File Decode Heap Overflow Vulnerability

vendor-disclosure wrote:
| [...]

There are two more similar loops that don't check the boundary of the
channel_info array.  The following patch should fix this as this seems
to be the only place where the PSD file is read.

--- psd.c~	2002-03-26 03:26:03.000000000 +0100
+++ psd.c	2005-01-14 11:36:06.000000000 +0100
     ThrowReaderException(CorruptImageWarning,"Not a PSD image file",image);
   (void) ReadBlob(image,6,(char *) psd_info.reserved);
   psd_info.channels=ReadBlobMSBShort(image);
+  if (psd_info.channels > 24) psd_info.channels = 24;
   psd_info.rows=ReadBlobMSBLong(image);
   psd_info.columns=ReadBlobMSBLong(image);
   psd_info.depth=ReadBlobMSBShort(image);

Mark, if this vulnerability will indeed be disclosed tomorrow, could
you assign a cve id for it?

Regards,

	Joey
Comment 2 Ludwig Nussel 2005-01-15 00:14:12 UTC
new CRD 17.01.2005 
Comment 3 Vladimir Nadvornik 2005-01-17 22:24:50 UTC
The patch is incomplete. There are two variables: psd_info.channels and 
layer_info[i].channels. 
It should look like this: 
 
 
--- coders/psd.c 
+++ coders/psd.c 
@@ -664,6 +664,7 @@ 
   } 
   (void) ReadBlob(image,6,psd_info.reserved); 
   psd_info.channels=ReadBlobMSBShort(image); 
+  if (psd_info.channels > 24) psd_info.channels = 24; 
   psd_info.rows=ReadBlobMSBLong(image); 
   psd_info.columns=ReadBlobMSBLong(image); 
   psd_info.depth=ReadBlobMSBShort(image); 
@@ -846,6 +847,7 @@ 
             layer_info[i].page.height=(ReadBlobMSBLong(image)-layer_info[i].page.y); 
             layer_info[i].page.width=(ReadBlobMSBLong(image)-layer_info[i].page.x); 
             layer_info[i].channels=ReadBlobMSBShort(image); 
+           if (layer_info[i].channels > 24) layer_info[i].channels = 24; 
           if (image->debug != MagickFalse) 
             (void) LogMagickEvent(CoderEvent,GetMagickModule(),"    
offset(%ld,%ld), size(%ld,%ld), channels=%d", 
               layer_info[i].page.x, layer_info[i].page.y, 
 
Comment 4 Marcus Meissner 2005-01-18 15:06:58 UTC
is public now. 
Comment 5 Vladimir Nadvornik 2005-01-18 18:31:56 UTC
Created attachment 27707 [details]
mainstream patch
Comment 6 Vladimir Nadvornik 2005-01-18 23:16:03 UTC
Packages are submitted. Can you please submit patchinfos? 
Comment 7 Ludwig Nussel 2005-01-18 23:26:58 UTC
CAN-2005-0005 
Comment 8 Marcus Meissner 2005-01-28 23:24:26 UTC
updates released