<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://bugs.gentoo.org/bugzilla.dtd">

<bugzilla version="2.22.7"
          urlbase="http://bugs.gentoo.org/"
          maintainer="bugzilla@gentoo.org"
>

    <bug>
          <bug_id>182047</bug_id>
          
          <creation_ts>2007-06-14 17:37 0000</creation_ts>
          <short_desc>media-gfx/gimp PSD Integer Overflow Vulnerability (CVE-{2007-2949|2006-4519})</short_desc>
          <delta_ts>2007-07-31 06:11:06 0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Gentoo Security</product>
          <component>Vulnerabilities</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <status_whiteboard>B2 [glsa] jaervosz</status_whiteboard>
          
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>jaervosz@gentoo.org</reporter>
          <assigned_to>security@gentoo.org</assigned_to>
          <cc>hanno@gentoo.org</cc>
    
    <cc>lars@chaotika.org</cc>
    
    <cc>mjf@gentoo.org</cc>

      

      
          <long_desc isprivate="0">
            <who>jaervosz@gentoo.org</who>
            <bug_when>2007-06-14 17:37:31 0000</bug_when>
            <thetext>there is a is an integer overflow in Gimp when loading PSD files.

Affected product: Gimp
Affected version: 2.2.15. Other versions may also be affected
CVE: CVE-2007-2949
SAID: 25677 (http://secunia.com/advisories/25677/)
Credit: Stefan Cornelius, Secunia Research
Disclosure date: Preliminary date set to Wed 27th June, 2007.



-- Background --

&quot;GIMP is the GNU Image Manipulation Program. It is a freely distributed 
piece of software for such tasks as photo retouching, image composition
and image authoring. It works on many operating systems.&quot;

PSD is an image file format originally used by Adobe Photoshop.
File format specifications can be found here: 
http://www.fileformat.info/format/psd/spec/index.htm



-- Analysis -- 

The vulnerability is caused due to an integer overflow within the 
function &quot;seek_to_and_unpack_pixeldata()&quot; in plug-ins/common/psd.c.
The file format documentation used during research states that valid
width and height values are between 1 and 30000. However, Gimp doesn&apos;t 
check that and uses the values in an insecure arithmetic function to
determine the amount of memory to allocate, which may be exploited to
cause a heap-based buffer overflow.

seek_to_and_unpack_pixeldata(FILE* fd, gint layeri, gint channeli) 
{
  int width, height; [1]
  guchar *tmpline;
  gint compression;
  guint32 offset = 0;
  PSDchannel *channel = &amp;psd_image.layer[layeri].channel[channeli];

  fsetpos(fd, &amp;channel-&gt;fpos); 

  compression = getgshort(fd, &quot;layer channel compression type&quot;);
  offset+=2;

  width = channel-&gt;width;     [2]
  height = channel-&gt;height;   [2]

  IFDBG
    {
      printf(&quot;\t\t\tLayer (%d) Channel (%d:%d) Compression: %d (%s)\n&quot;, 
         layeri,
         channeli,
         channel-&gt;type,
         compression,
         compression==0?&quot;raw&quot;:(compression==1?&quot;RLE&quot;:&quot;*UNKNOWN!*&quot;));

      fflush(stdout); 
    }

  channel-&gt;data = g_malloc (width * height);   [3]

  tmpline = g_malloc(width + 1);

  switch (compression)
    {
    case 0: /* raw data */
      {
    gint linei;

    for (linei = 0; linei &lt; height; linei++) 
      {
        xfread(fd, channel-&gt;data + linei * width, width,
           &quot;raw channel line&quot;);     [4]
        offset += width;
      }

#if 0
    /* Pad raw data to multiple of 2? */ 
    if ((height * width) &amp; 1)
      {
        getguchar(fd, &quot;raw channel padding&quot;);
        offset++;
      }
#endif
      }
      break;
    case 1: /* RLE, one row at a time, padded to an even width */ 
      {

----

[1] define variables width and height 
[2] assign unchecked values to the variables
[3] multiply width and height, use result to allocate memory.
     If width and height are certain large values, this will
     overflow and an insufficient amount of memory is allocated. 
[4] Load data from file and copy it into the buffer. (In this case
     for the uncompressed format - RLE encoded files may also be
     affected).



-- Exploitation --

The vulnerability can be exploited to cause a heap-based buffer overflow
by e.g. tricking a user into opening a specially crafted PSD file with
certain width and height information. 

Successful exploitation may allow execution of arbitrary code.


Credits should be given to:
Stefan Cornelius, Secunia Research.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>jaervosz@gentoo.org</who>
            <bug_when>2007-06-14 17:41:15 0000</bug_when>
            <thetext>Friendly reminder: waiting for upstream and please don&apos;t commit anything before the 27th.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>hanno@gentoo.org</who>
            <bug_when>2007-07-02 13:18:40 0000</bug_when>
            <thetext>has this been delayed? didn&apos;t see a public advisory anywhere.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>aetius@gentoo.org</who>
            <bug_when>2007-07-03 21:11:31 0000</bug_when>
            <thetext>It&apos;s public now.

http://secunia.com/advisories/25677/</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>hanno@gentoo.org</who>
            <bug_when>2007-07-08 00:27:27 0000</bug_when>
            <thetext>*** Bug 184141 has been marked as a duplicate of this bug. ***</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>hanno@gentoo.org</who>
            <bug_when>2007-07-08 00:50:21 0000</bug_when>
            <thetext>gimp 2.2.16 added, archs, please mark stable.

security, please make this bug public.

A problem is with 2.3.x. Upstream hasn&apos;t released an update and it seems that it&apos;s more than just one integer overflow (and they aren&apos;t documented properly). I think we can just wait for a new 2.3.x-release.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>corsair@gentoo.org</who>
            <bug_when>2007-07-10 06:16:43 0000</bug_when>
            <thetext>ppc64  stable</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>jer@gentoo.org</who>
            <bug_when>2007-07-10 07:13:23 0000</bug_when>
            <thetext>Stable for HPPA.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>fauli@gentoo.org</who>
            <bug_when>2007-07-10 08:55:05 0000</bug_when>
            <thetext>x86 stable</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>armin76@gentoo.org</who>
            <bug_when>2007-07-10 14:21:30 0000</bug_when>
            <thetext>alpha/ia64 stable</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>gustavoz@gentoo.org</who>
            <bug_when>2007-07-10 14:42:01 0000</bug_when>
            <thetext>sparc stable.
</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>angelos@gentoo.org</who>
            <bug_when>2007-07-11 12:03:27 0000</bug_when>
            <thetext>amd64 stable</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>dertobi123@gentoo.org</who>
            <bug_when>2007-07-11 17:23:16 0000</bug_when>
            <thetext>ppc stable, ready for GLSA.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>hanno@gentoo.org</who>
            <bug_when>2007-07-13 02:07:57 0000</bug_when>
            <thetext>*** Bug 184782 has been marked as a duplicate of this bug. ***</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>falco@gentoo.org</who>
            <bug_when>2007-07-25 21:21:26 0000</bug_when>
            <thetext>GLSA 200707-09</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <who>kumba@gentoo.org</who>
            <bug_when>2007-07-31 06:11:06 0000</bug_when>
            <thetext>mips stable.</thetext>
          </long_desc>
      
    </bug>

</bugzilla>