Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 112937 - media-libs/gd: gd-2.0.32 integer overflows in gdImageCreate(), gdImageCreateTrueColor()
Summary: media-libs/gd: gd-2.0.32 integer overflows in gdImageCreate(), gdImageCreateT...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Security
Classification: Unclassified
Component: Vulnerabilities (show other bugs)
Hardware: All Linux
: High minor
Assignee: Gentoo Security
URL: http://cve.mitre.org/cgi-bin/cvename....
Whiteboard: B3 [noglsa]
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-18 10:40 UTC by Alexey Dobriyan
Modified: 2019-12-01 21:29 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Fix integer overflow (gd.patch,1.28 KB, patch)
2005-12-05 16:07 UTC, Alexey Dobriyan
no flags Details | Diff
Part of libgd2_2.0.33-1.1.diff.gz from Debian (libgd2_2.0.33-1.1.diff,3.74 KB, patch)
2005-12-14 09:24 UTC, Alexey Dobriyan
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Dobriyan 2005-11-18 10:40:12 UTC
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 Tavis Ormandy (RETIRED) gentoo-dev 2005-12-05 13:36:19 UTC
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 Alexey Dobriyan 2005-12-05 16:07:53 UTC
Created attachment 74122 [details, diff]
Fix integer overflow

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

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

sorry.
Comment 3 SpanKY gentoo-dev 2005-12-05 17:06:48 UTC
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 Thierry Carrez (RETIRED) gentoo-dev 2005-12-09 07:01:26 UTC
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 Thierry Carrez (RETIRED) gentoo-dev 2005-12-11 09:19:59 UTC
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 SpanKY gentoo-dev 2005-12-11 19:33:57 UTC
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 Thierry Carrez (RETIRED) gentoo-dev 2005-12-14 07:39:53 UTC
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 Alexey Dobriyan 2005-12-14 09:22:43 UTC
Looks like they open-coded overflow2(). Attaching interesting part FYI.
Comment 9 Alexey Dobriyan 2005-12-14 09:24:21 UTC
Created attachment 74735 [details, diff]
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 Thierry Carrez (RETIRED) gentoo-dev 2005-12-20 04:11:02 UTC
vapier: please check and bump
Comment 11 SpanKY gentoo-dev 2005-12-20 06:26:48 UTC
read my comment #3 :P

ive had this done locally, i just asked for feedback a while ago
Comment 12 Thierry Carrez (RETIRED) gentoo-dev 2005-12-20 08:06:00 UTC
Apparently nobody wants to doublecheck your patch. Looks good to me but I'm pointer-impaired. So commit it :)
Comment 13 SpanKY gentoo-dev 2005-12-20 17:55:16 UTC
added 2.0.33 to cvs
Comment 14 Stefan Cornelius (RETIRED) gentoo-dev 2005-12-20 22:17:22 UTC
arches, please test and mark stable - thx
Comment 15 Stefan Cornelius (RETIRED) gentoo-dev 2005-12-20 22:18:59 UTC
... note to self: don't fight bugs without your morning coffee, sorry.
Comment 16 Markus Rothe (RETIRED) gentoo-dev 2005-12-20 22:29:51 UTC
stable on ppc64
Comment 17 Mark Loeser (RETIRED) gentoo-dev 2005-12-20 23:04:17 UTC
x86 done
Comment 18 Fernando J. Pereda (RETIRED) gentoo-dev 2005-12-21 02:06:32 UTC
alpha'lized

Cheers,
Ferdy
Comment 19 Gustavo Zacarias (RETIRED) gentoo-dev 2005-12-21 05:05:26 UTC
sparc stable.
Comment 20 Marcus D. Hanwell (RETIRED) gentoo-dev 2005-12-21 06:20:09 UTC
Stable on amd64.
Comment 21 Michael Hanselmann (hansmi) (RETIRED) gentoo-dev 2005-12-22 11:39:35 UTC
Stable on ppc.
Comment 22 Stefan Cornelius (RETIRED) gentoo-dev 2005-12-22 11:43:37 UTC
ready for glsa. tend to say no here because taviso said that it's probably not exploitable.
Comment 23 Thierry Carrez (RETIRED) gentoo-dev 2005-12-23 00:27:17 UTC
Half yes, for the crash possibility (mod_php and other webapps).
Comment 24 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2005-12-28 01:38:15 UTC

    
Comment 25 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2005-12-28 01:38:15 UTC
½ NO from me.
Comment 26 Thierry Carrez (RETIRED) gentoo-dev 2005-12-28 02:24:43 UTC
Reverting to no and closing.