pajoye Sun Dec 25 19:21:58 2005 EDT Added files: /php-src/ext/gd/tests colorexact.phpt colormatch.phpt
Modified files: /php-src/ext/gd gd.c /php-src/ext/gd/libgd gd_topal.c Log: - fix leak/segfaults in imagecolormatch - add tests for imagecolorexact and imagecolormatch The later is only about the segv http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/gd.c?r1=1.329&r2=1.330&diff_format=u Index: php-src/ext/gd/gd.c diff -u php-src/ext/gd/gd.c:1.329 php-src/ext/gd/gd.c:1.330 --- php-src/ext/gd/gd.c:1.329 Thu Dec 22 23:22:26 2005 +++ php-src/ext/gd/gd.c Sun Dec 25 19:21:57 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: gd.c,v 1.329 2005/12/22 23:22:26 pajoye Exp $ */ +/* $Id: gd.c,v 1.330 2005/12/25 19:21:57 pajoye Exp $ */ /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center, Cold Spring Harbor Labs. */ @@ -822,6 +822,10 @@ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Image1 and Image2 must be the same size" ); RETURN_FALSE; break; + case -4: + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Image2 must have at least one color" ); + RETURN_FALSE; + break; } RETURN_TRUE; http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/libgd/gd_topal.c?r1=1.17&r2=1.18&diff_format=u Index: php-src/ext/gd/libgd/gd_topal.c diff -u php-src/ext/gd/libgd/gd_topal.c:1.17 php-src/ext/gd/libgd/gd_topal.c:1.18 --- php-src/ext/gd/libgd/gd_topal.c:1.17 Wed Aug 11 23:25:50 2004 +++ php-src/ext/gd/libgd/gd_topal.c Sun Dec 25 19:21:57 2005 @@ -2086,6 +2086,9 @@ if( (im1->sx != im2->sx) || (im1->sy != im2->sy) ) { return -3; /* the images are meant to be the same dimensions */ } + if (im2->colorsTotal<1) { + return -4; /* At least 1 color must be allocated */ + } buf = (unsigned long *)safe_emalloc(sizeof(unsigned long), 5 * im2->colorsTotal, 0); memset( buf, 0, sizeof(unsigned long) * 5 * im2->colorsTotal ); http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/tests/colorexact.phpt?view=markup&rev=1.1 Index: php-src/ext/gd/tests/colorexact.phpt +++ php-src/ext/gd/tests/colorexact.phpt --TEST-- imagecolorexact --SKIPIF-- <?php if (!function_exists('imagecolorexact')) die("skip gd extension not available\n"); ?> --FILE-- <?php $im = imagecreatetruecolor(5,5); $c = imagecolorexact($im, 255,0,255); $c2 = imagecolorexactalpha($im, 255,0,255, 100); printf("%X\n", $c); printf("%X\n", $c2); imagedestroy($im); $im = imagecreate(5,5); $c = imagecolorallocate($im, 255,0,255); $c2 = imagecolorallocate($im, 255,200,0); $c3 = imagecolorallocatealpha($im, 255,200,0,100); echo imagecolorexact($im, 255,0,255) . "\n"; echo imagecolorexact($im, 255,200,0) . "\n"; echo imagecolorexactalpha($im, 255,200,0,100) . "\n"; // unallocated index echo imagecolorexact($im, 12,12,12) . "\n"; imagedestroy($im); ?> --EXPECTF-- FF00FF 64FF00FF 0 1 2 -1 http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/tests/colormatch.phpt?view=markup&rev=1.1 Index: php-src/ext/gd/tests/colormatch.phpt +++ php-src/ext/gd/tests/colormatch.phpt --TEST-- imagecolormatch --SKIPIF-- <?php if (!function_exists('imagecolormatch')) die("skip gd extension not available\n"); ?> --FILE-- <?php $im = imagecreatetruecolor(5,5); $im2 = imagecreate(5,5); imagecolormatch($im, $im2); echo "ok\n"; imagedestroy($im); ?> --EXPECTF-- Fatal error: imagecolormatch(): Image2 must have at least one color in %s on line %d -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php