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: Wed, 17 Aug 2016 11:46:14 +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-93897@lists.php.net to get a copy of this message
Commit: 3493ed5b528be73c73a85c75effdfd3a469ac55d Author: Anatol Belski <ab@php.net> Tue, 16 Aug 2016 14:37:39 +0200 Parents: 72d03f8aa460184930cbca3f61de3cec35128e2b Branches: PHP-7.0.10 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3493ed5b528be73c73a85c75effdfd3a469ac55d Log: Fix bug#72697 - select_colors write out-of-bounds (cherry picked from commit b6f13a5ef9d6280cf984826a5de012a32c396cd4) Conflicts: ext/gd/gd.c (cherry picked from commit 28022c9b1fd937436ab67bb3d61f652c108baf96) 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 3faea95...27dce95 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -1530,11 +1530,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 (#93897) next »