Bug 112937 - media-libs/gd: gd-2.0.32 integer overflows in gdImageCreate(), gdImageCreateTrueColor()
Bug#: 112937 Product:  Gentoo Security Version: unspecified Platform: All
OS/Version: Linux Status: RESOLVED Severity: minor Priority: P2
Resolution: FIXED Assigned To: security@gentoo.org Reported By: adobriyan@gmail.com
Component: Vulnerabilities
URL:  http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-0941
Summary: media-libs/gd: gd-2.0.32 integer overflows in gdImageCreate(), gdImageCreateTrueColor()
Keywords:  
Status Whiteboard: B3 [noglsa]
Opened: 2005-11-18 10:40 0000
Description:   Opened: 2005-11-18 10:40 0000
gd.c:
    70	BGD_DECLARE(gdImagePtr) gdImageCreate (int sx, int sy)
    71	{
    72	  int i;
    73	  gdImagePtr im;
    74	  im = (gdImage *) gdMalloc (sizeof (gdImage));
    75	  memset (im, 0, sizeof (gdImage));
    76	  /* Row-major ever since gd 1.3 */
    77	  im->pixels = (unsigned char **) gdMalloc (sizeof (unsigned char *) * sy);

gdImageCreate() is called from gdImageCreateFromXbm() with "sy" directly from
.xbm file.

   111	BGD_DECLARE(gdImagePtr) gdImageCreateTrueColor (int sx, int sy)
   112	{
   113	  int i;
   114	  gdImagePtr im;
   115	  im = (gdImage *) gdMalloc (sizeof (gdImage));
   116	  memset (im, 0, sizeof (gdImage));
   117	  im->tpixels = (int **) gdMalloc (sizeof (int *) * sy);
-----------------------------------------------------------------------
Steps to reproduce:

1.c:
-----------------------------------------
#include <stdio.h>
#include <gd.h>

int main(void)
{
	FILE *f;

	f = fopen("1.xbm", "rb");
	gdImageCreateFromXbm(f);
	return 0;
}
-----------------------------------------
gcc -o 1 1.c -lgd

1.xbm: (3 lines)
-----------------------------------------
#define a 1
#define b 1073741824

-----------------------------------------
./1

------- Comment #1 From Tavis Ormandy (RETIRED) 2005-12-05 13:36:19 0000 -------
There's definitely a heap overflow there, but it looks very difficult 
(impossible?) to exploit, the allocated chunk is filled up with pointers 
returned from more calls to malloc so no direct control over what's written 
there.

Nevertheless, it's a bug, and you could cause a linked application to crash 
(mod_php?), so this needs to be fixed. handing it over to vulnerabilities.

------- Comment #2 From Alexey Dobriyan 2005-12-05 16:07:53 0000 -------
Created an attachment (id=74122) [details]
Fix integer overflow

Ohhh... something is missing. The patch. ;-)

Thorough check of gdImageCreateTrueColor() return values will be done tomorrow,

sorry.

------- Comment #3 From SpanKY 2005-12-05 17:06:48 0000 -------
patch looks good to me ... if someone else wants to peek at it real quick, i'll
hold adding gd-2.0.33 until they do ...

------- Comment #4 From Thierry Carrez (RETIRED) 2005-12-09 07:01:26 0000 -------
Reporter : you should push this to vendor-sec@lst.de, they might be interested.
We can do it if you prefer, the idea being to set a public disclosure date for
all security releases, like +7 days.

------- Comment #5 From Thierry Carrez (RETIRED) 2005-12-11 09:19:59 0000 -------
OK this is an old one that never made it upstream (CVE-2004-0941). Probably
better to check the old complete patches to see nothing else slipped through ?

------- Comment #6 From SpanKY 2005-12-11 19:33:57 0000 -------
err, i dont think it's those issues ... we've had overflows in the png routines
before, but i dont think anyone has mentioned xbm before

also, if we fix up the core create functions, we might be able to back out some
of the sanity checks in the png layers ... but i'd have to review the code again
to be sure ...

------- Comment #7 From Thierry Carrez (RETIRED) 2005-12-14 07:39:53 0000 -------
It's been fixed under that name on Debian :
http://ftp.debian.org/debian/pool/main/libg/libgd2/libgd2_2.0.33-1.1.diff.gz

Maybe extract the fixorz from their patchset ?

------- Comment #8 From Alexey Dobriyan 2005-12-14 09:22:43 0000 -------
Looks like they open-coded overflow2(). Attaching interesting part FYI.

------- Comment #9 From Alexey Dobriyan 2005-12-14 09:24:21 0000 -------
Created an attachment (id=74735) [details]
Part of libgd2_2.0.33-1.1.diff.gz from Debian

 gd.c	    |	11 ++++++++++-
 gd_gd.c    |	 4 ++++
 gd_io_dp.c |	 4 +++-
 gd_png.c   |	 5 +++++
 gdxpm.c    |	 5 +++++
 wbmp.c     |	12 ++++++++----
 6 files changed, 35 insertions(+), 6 deletions(-)

------- Comment #10 From Thierry Carrez (RETIRED) 2005-12-20 04:11:02 0000 -------
vapier: please check and bump

------- Comment #11 From SpanKY 2005-12-20 06:26:48 0000 -------
read my comment #3 :P

ive had this done locally, i just asked for feedback a while ago

------- Comment #12 From Thierry Carrez (RETIRED) 2005-12-20 08:06:00 0000 -------
Apparently nobody wants to doublecheck your patch. Looks good to me but I'm
pointer-impaired. So commit it :)

------- Comment #13 From SpanKY 2005-12-20 17:55:16 0000 -------
added 2.0.33 to cvs

------- Comment #14 From Stefan Cornelius (RETIRED) 2005-12-20 22:17:22 0000 -------
arches, please test and mark stable - thx

------- Comment #15 From Stefan Cornelius (RETIRED) 2005-12-20 22:18:59 0000 -------
... note to self: don't fight bugs without your morning coffee, sorry.

------- Comment #16 From Markus Rothe 2005-12-20 22:29:51 0000 -------
stable on ppc64

------- Comment #17 From Mark Loeser 2005-12-20 23:04:17 0000 -------
x86 done

------- Comment #18 From Fernando J. Pereda (RETIRED) 2005-12-21 02:06:32 0000 -------
alpha'lized

Cheers,
Ferdy

------- Comment #19 From Gustavo Zacarias (RETIRED) 2005-12-21 05:05:26 0000 -------
sparc stable.

------- Comment #20 From Marcus D. Hanwell 2005-12-21 06:20:09 0000 -------
Stable on amd64.

------- Comment #21 From Michael Hanselmann (hansmi) (RETIRED) 2005-12-22 11:39:35 0000 -------
Stable on ppc.

------- Comment #22 From Stefan Cornelius (RETIRED) 2005-12-22 11:43:37 0000 -------
ready for glsa. tend to say no here because taviso said that it's probably not
exploitable.

------- Comment #23 From Thierry Carrez (RETIRED) 2005-12-23 00:27:17 0000 -------
Half yes, for the crash possibility (mod_php and other webapps).

------- Comment #24 From Sune Kloppenborg Jeppesen 2005-12-28 01:38:15 0000 -------

    

------- Comment #25 From Sune Kloppenborg Jeppesen 2005-12-28 01:38:15 0000 -------
½ NO from me.

------- Comment #26 From Thierry Carrez (RETIRED) 2005-12-28 02:24:43 0000 -------
Reverting to no and closing.