cvs: gd /libgd/src gd_tiff.c

From: Date: Thu, 04 Oct 2007 21:49:51 +0000
Subject: cvs: gd /libgd/src gd_tiff.c
Groups: php.gd.cvs 
Request: Send a blank email to php-gd-cvs+get-294@lists.php.net to get a copy of this message
mattias Thu Oct 4 21:49:51 2007 UTC Modified files: /gd/libgd/src gd_tiff.c Log: - Added checking for allocation http://cvs.php.net/viewvc.cgi/gd/libgd/src/gd_tiff.c?r1=1.4&r2=1.5&diff_format=u Index: gd/libgd/src/gd_tiff.c diff -u gd/libgd/src/gd_tiff.c:1.4 gd/libgd/src/gd_tiff.c:1.5 --- gd/libgd/src/gd_tiff.c:1.4 Thu Oct 4 21:37:45 2007 +++ gd/libgd/src/gd_tiff.c Thu Oct 4 21:49:51 2007 @@ -25,7 +25,7 @@ ---------------------------------------------------------------------------- */ -/* $Id: gd_tiff.c,v 1.4 2007/10/04 21:37:45 mattias Exp $ */ +/* $Id: gd_tiff.c,v 1.5 2007/10/04 21:49:51 mattias Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -66,7 +66,9 @@ tiff_handle *new_tiff_handle(tiff_handle *t, gdIOCtx *g) { - t = gdMalloc(sizeof(tiff_handle)); + if(!t || !g || (t = gdMalloc(sizeof(tiff_handle)))) { + return 0; + } t->size = 0; t->pos = 0; @@ -239,6 +241,7 @@ /* build the color map for 8 bit images */ if(bitDepth != 24) { + /*TODO: Add checking */ colorMapRed = gdMalloc(3 * pow(2, bitsPerSample)); colorMapGreen = gdMalloc(3 * pow(2, bitsPerSample)); colorMapBlue = gdMalloc(3 * pow(2, bitsPerSample)); @@ -268,8 +271,15 @@ TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, 1); + if(overflow2(width, samplesPerPixel)) { + return 0; + } + + if(!(scan = gdMalloc(width * samplesPerPixel))) { + return 0; + } + /* loop through y-coords, and x-coords */ - scan = gdMalloc(width * samplesPerPixel); for(y = 0; y < height; y++) { for(x = 0; x < width; x++) { /* generate scan line for writing to tiff */ @@ -456,7 +466,9 @@ TIFFGetField(tiff, TIFFTAG_TILELENGTH, &tileMaxY); tileSize = TIFFTileSize(tiff); - scan = gdMalloc(tileSize); + if(!(scan = gdMalloc(tileSize))) { + return 0; + } tileX = 0; tileY = 0; for(tileNum = 0; tileNum < numberOfTiles; tileNum++) { @@ -515,7 +527,9 @@ } else { /* image is not tiled - assume stripped (scanline) format */ printf("is a 1bit scanline tiff!\n"); - scan = gdMalloc(TIFFScanlineSize(tiff)); + if(!(scan = gdMalloc(TIFFScanlineSize(tiff)))) { + return 0; + } y = x = 0; for(i = 0; i < height; i++) { @@ -598,7 +612,9 @@ TIFFGetField(tiff, TIFFTAG_TILELENGTH, &tileMaxY); tileSize = TIFFTileSize(tiff); - scan = gdMalloc(tileSize); + if(!(scan = gdMalloc(tileSize))) { + return 0; + } tileX=0; tileY=0; @@ -648,7 +664,9 @@ gdFree(scan); } else { - scan = gdMalloc(TIFFScanlineSize(tiff)); + if(!(scan = gdMalloc(TIFFScanlineSize(tiff)))) { + return 0; + } y=0; x=0;

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