com php-src: Fix bug#72697 - select_colors write out-of-b ounds: ext/gd/gd.c ext/gd/tests/bug72697.ph pt

From: Date: Tue, 16 Aug 2016 12:37:39 +0000
Subject: com php-src: Fix bug#72697 - select_colors write out-of-b ounds: ext/gd/gd.c ext/gd/tests/bug72697.ph pt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-93852@lists.php.net to get a copy of this message
Commit: 28022c9b1fd937436ab67bb3d61f652c108baf96 Author: Anatol Belski <ab@php.net> Tue, 16 Aug 2016 14:37:39 +0200 Parents: b735a4419c1e796520b395a2aa0b6943d9157b73 Branches: PHP-7.0 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=28022c9b1fd937436ab67bb3d61f652c108baf96 Log: Fix bug#72697 - select_colors write out-of-bounds (cherry picked from commit b6f13a5ef9d6280cf984826a5de012a32c396cd4) Conflicts: ext/gd/gd.c Bugs: https://bugs.php.net/72697 Changed paths: M ext/gd/gd.c A ext/gd/tests/bug72697.phpt Diff: diff --git a/ext/gd/gd.c b/ext/gd/gd.c index c952ee9..0346a74 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -1537,11 +1537,11 @@ PHP_FUNCTION(imagetruecolortopalette) RETURN_FALSE; } - if (ncolors <= 0) { - php_error_docref(NULL, E_WARNING, "Number of colors has to be greater than zero"); + if (ncolors <= 0 || ZEND_LONG_INT_OVFL(ncolors)) { + php_error_docref(NULL, E_WARNING, "Number of colors has to be greater than zero and no more than %d", INT_MAX); RETURN_FALSE; } - gdImageTrueColorToPalette(im, dither, ncolors); + gdImageTrueColorToPalette(im, dither, (int)ncolors); RETURN_TRUE; } diff --git a/ext/gd/tests/bug72697.phpt b/ext/gd/tests/bug72697.phpt new file mode 100644 index 0000000..6110385 --- /dev/null +++ b/ext/gd/tests/bug72697.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #72697: select_colors write out-of-bounds +--SKIPIF-- +<?php +if (!function_exists("imagecreatetruecolor")) die("skip"); +if (PHP_INT_MAX !== 9223372036854775807) die("skip for 64-bit long systems only"); +?> +--FILE-- +<?php + +$img=imagecreatetruecolor(10, 10); +imagetruecolortopalette($img, false, PHP_INT_MAX / 8); +?> +DONE +--EXPECTF-- +Warning: imagetruecolortopalette(): Number of colors has to be greater than zero and no more than 2147483647 in %sbug72697.php on line %d +DONE \ No newline at end of file

« previous php.cvs (#93852) next »