cvs: gd /libgd ISSUES gd_gd2.c

From: Date: Wed, 03 Jan 2007 21:42:02 +0000
Subject: cvs: gd /libgd ISSUES gd_gd2.c
Groups: php.gd.cvs 
Request: Send a blank email to php-gd-cvs+get-60@lists.php.net to get a copy of this message
pajoye Wed Jan 3 21:42:02 2007 UTC Modified files: /gd/libgd gd_gd2.c ISSUES Log: #32, Added sanity checks for allocations failures in gd_gd2 http://cvs.php.net/viewvc.cgi/gd/libgd/gd_gd2.c?r1=1.19&r2=1.20&diff_format=u Index: gd/libgd/gd_gd2.c diff -u gd/libgd/gd_gd2.c:1.19 gd/libgd/gd_gd2.c:1.20 --- gd/libgd/gd_gd2.c:1.19 Wed Apr 5 15:54:20 2006 +++ gd/libgd/gd_gd2.c Wed Jan 3 21:42:02 2007 @@ -171,6 +171,9 @@ GD2_DBG (printf ("Reading %d chunk index entries\n", nc)); sidx = sizeof (t_chunk_info) * nc; cidx = gdCalloc (sidx, 1); + if (!cidx) { + goto fail1; + } for (i = 0; i < nc; i++) { if (gdGetInt (&cidx[i].offset, in) != 1) @@ -322,7 +325,8 @@ if (im == NULL) { return 0; - }; + } + bytesPerPixel = im->trueColor ? 4 : 1; nc = ncx * ncy; @@ -342,7 +346,14 @@ /* Allocate buffers */ chunkMax = cs * bytesPerPixel * cs; chunkBuf = gdCalloc (chunkMax, 1); + if (!chunkBuf) { + goto fail2; + } compBuf = gdCalloc (compMax, 1); + if (!compBuf) { + goto fail2; + } + GD2_DBG (printf ("Largest compressed chunk is %d bytes\n", compMax)); }; @@ -462,11 +473,17 @@ fail2: gdImageDestroy (im); - gdFree (chunkBuf); - gdFree (compBuf); - gdFree (chunkIdx); +fail1: + if (chunkBuf) { + gdFree (chunkBuf); + } + if (compBuf) { + gdFree (compBuf); + } + if (chunkIdx) { + gdFree (chunkIdx); + } return 0; - } BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Part (FILE * inFile, int srcx, int srcy, int w, int h) @@ -571,7 +588,14 @@ chunkMax = cs * cs; } chunkBuf = gdCalloc (chunkMax, 1); + if (!chunkBuf) { + goto fail2; + } compBuf = gdCalloc (compMax, 1); + if (!compBuf) { + goto fail2; + } + }; /* Don't bother with this... */ @@ -748,10 +772,15 @@ fail2: gdImageDestroy (im); fail1: - gdFree (chunkBuf); - gdFree (compBuf); - gdFree (chunkIdx); - + if (chunkBuf) { + gdFree (chunkBuf); + } + if (compBuf) { + gdFree (compBuf); + } + if (chunkIdx) { + gdFree (chunkIdx); + } return 0; } @@ -851,7 +880,13 @@ /* Allocate the buffers. */ /* */ chunkData = gdCalloc (cs * bytesPerPixel * cs, 1); + if (!chunkData) { + goto fail; + } compData = gdCalloc (compMax, 1); + if (!compData) { + goto fail; + } /* */ /* Save the file position of chunk index, and allocate enough space for */ @@ -984,13 +1019,20 @@ gdSeek (out, posSave); }; + /*printf("Memory block size is %d\n",gdTell(out)); */ +fail: GD2_DBG (printf ("Freeing memory\n")); - gdFree (chunkData); - gdFree (compData); - gdFree (chunkIdx); - GD2_DBG (printf ("Done\n")); - /*printf("Memory block size is %d\n",gdTell(out)); */ + if (chunkData) { + gdFree (chunkData); + } + if (compData) { + gdFree (compData); + } + if (chunkIdx) { + gdFree (chunkIdx); + } + GD2_DBG (printf ("Done\n")); } http://cvs.php.net/viewvc.cgi/gd/libgd/ISSUES?r1=1.27&r2=1.28&diff_format=u Index: gd/libgd/ISSUES diff -u gd/libgd/ISSUES:1.27 gd/libgd/ISSUES:1.28 --- gd/libgd/ISSUES:1.27 Wed Jan 3 21:24:59 2007 +++ gd/libgd/ISSUES Wed Jan 3 21:42:02 2007 @@ -60,3 +60,4 @@ at very small dpi values (John Ellson/Graphviz) #31, Added DISABLE_THREADS to permit disabling of thread support (John Ellson/Graphviz) +#32, Added sanity checks for allocations failure in gd_gd2

« previous php.gd.cvs (#60) next »