helly Wed Feb 23 19:12:15 2005 EDT Modified files: /php-src/ext/standard image.c Log: - Prevent superflous memory allocation http://cvs.php.net/diff.php/php-src/ext/standard/image.c?r1=1.104&r2=1.105&ty=u Index: php-src/ext/standard/image.c diff -u php-src/ext/standard/image.c:1.104 php-src/ext/standard/image.c:1.105 --- php-src/ext/standard/image.c:1.104 Wed Feb 23 18:39:36 2005 +++ php-src/ext/standard/image.c Wed Feb 23 19:12:15 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: image.c,v 1.104 2005/02/23 23:39:36 iliaa Exp $ */ +/* $Id: image.c,v 1.105 2005/02/24 00:12:15 helly Exp $ */ #include "php.h" #include <stdio.h> @@ -867,10 +867,11 @@ */ static struct gfxinfo *php_handle_iff(php_stream * stream TSRMLS_DC) { - struct gfxinfo *result = NULL; + struct gfxinfo * result; unsigned char a[10]; int chunkId; int size; + short width, height, bits; if (php_stream_read(stream, a, 8) != 8) { return NULL; @@ -893,18 +894,20 @@ size++; } if (chunkId == 0x424d4844) { /* BMHD chunk */ - if (php_stream_read(stream, a, 9) != 9) { + if (size < 9 || php_stream_read(stream, a, 9) != 9) { return NULL; } - result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo)); - result->width = php_ifd_get16s(a+0, 1); - result->height = php_ifd_get16s(a+2, 1); - result->bits = a[8] & 0xff; - result->channels = 0; - if (result->width > 0 && result->height > 0 && result->bits > 0 && result->bits < 33) { + width = php_ifd_get16s(a+0, 1); + height = php_ifd_get16s(a+2, 1); + bits = a[8] & 0xff; + if (width > 0 && height > 0 && bits > 0 && bits < 33) { + result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo)); + result->width = width; + result->height = height; + result->bits = bits; + result->channels = 0; return result; } - efree(result); } else { if (php_stream_seek(stream, size, SEEK_CUR)) { return NULL;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php