From: Mark Date: Wed, 4 Sep 2019 00:09:41 +0000 (+0200) Subject: Warnings for image colour range check now throw exceptions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=af8ecb39aee0cb8dd751d0a1d3d03d165ab60589;p=php Warnings for image colour range check now throw exceptions --- diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 3aead99242..0837f83084 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -1109,8 +1109,8 @@ PHP_FUNCTION(imagelayereffect) #define CHECK_RGBA_RANGE(component, name) \ if (component < 0 || component > gd##name##Max) { \ - php_error_docref(NULL, E_WARNING, #name " component is out of range"); \ - RETURN_FALSE; \ + zend_throw_error(NULL, #name " component is out of range, must be between 0 and %d (inclusive)", gd##name##Max); \ + return; \ } /* {{{ proto int imagecolorallocatealpha(resource im, int red, int green, int blue, int alpha) diff --git a/ext/gd/tests/imagecolorallocate_variation5.phpt b/ext/gd/tests/imagecolorallocate_variation5.phpt index ac3e4bb20e..7d4b941069 100644 --- a/ext/gd/tests/imagecolorallocate_variation5.phpt +++ b/ext/gd/tests/imagecolorallocate_variation5.phpt @@ -11,6 +11,8 @@ if(!function_exists('imagecreatetruecolor')) { ?> --FILE-- $value) { - echo "\n--$key--\n"; - var_dump( imagecolorallocate($im, $value, $green, $blue) ); - var_dump( imagecolorallocate($im, $red, $value, $blue) ); - var_dump( imagecolorallocate($im, $red, $green, $value) ); + echo "\n--$key--\n"; + + trycatch_dump( + fn() => imagecolorallocate($im, $value, $green, $blue), + fn() => imagecolorallocate($im, $red, $value, $blue), + fn() => imagecolorallocate($im, $red, $green, $value) + ); }; ?> ===DONE=== ---EXPECTF-- +--EXPECT-- *** Testing imagecolorallocate() : usage variations *** --Octal 000-- @@ -59,15 +64,9 @@ int(657930) int(657930) --Octal -012-- - -Warning: imagecolorallocate(): Red component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Green component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Blue component is out of range in %s on line %d -bool(false) +!! [Error] Red component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Green component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive) --Octal 0377-- int(16714250) @@ -85,15 +84,9 @@ int(657930) int(657930) --Hexa-decimal -0xA-- - -Warning: imagecolorallocate(): Red component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Green component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Blue component is out of range in %s on line %d -bool(false) +!! [Error] Red component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Green component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive) --Hexa-decimal 0xFF-- int(16714250) diff --git a/ext/gd/tests/imagecolorallocate_variation6.phpt b/ext/gd/tests/imagecolorallocate_variation6.phpt index a3649be71f..6b2eb8ba2f 100644 --- a/ext/gd/tests/imagecolorallocate_variation6.phpt +++ b/ext/gd/tests/imagecolorallocate_variation6.phpt @@ -11,6 +11,8 @@ if(!function_exists('imagecreatetruecolor')) { ?> --FILE-- $value) { //Need to be created every time to get expected return value $im_palette = imagecreate(200, 200); $im_true_color = imagecreatetruecolor(200, 200); - var_dump( imagecolorallocate($im_palette, $value, 0, 0) ); - var_dump( imagecolorallocate($im_true_color, $value, 0, 0) ); - var_dump( imagecolorallocate($im_palette, 0, $value, 0) ); - var_dump( imagecolorallocate($im_true_color, 0, $value, 0) ); - var_dump( imagecolorallocate($im_palette, 0, 0, $value) ); - var_dump( imagecolorallocate($im_true_color, 0, 0, $value) ); + + trycatch_dump( + fn() => imagecolorallocate($im_palette, $value, 0, 0), + fn() => imagecolorallocate($im_true_color, $value, 0, 0), + fn() => imagecolorallocate($im_palette, 0, $value, 0), + fn() => imagecolorallocate($im_true_color, 0, $value, 0), + fn() => imagecolorallocate($im_palette, 0, 0, $value), + fn() => imagecolorallocate($im_true_color, 0, 0, $value) + ); }; ?> ===DONE=== ---EXPECTF-- +--EXPECT-- *** Testing imagecolorallocate() : usage variations *** --Decimal 256-- - -Warning: imagecolorallocate(): Red component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Red component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Green component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Green component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Blue component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Blue component is out of range in %s on line %d -bool(false) +!! [Error] Red component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Red component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Green component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Green component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive) --Octal 0400-- - -Warning: imagecolorallocate(): Red component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Red component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Green component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Green component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Blue component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Blue component is out of range in %s on line %d -bool(false) +!! [Error] Red component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Red component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Green component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Green component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive) --Hexa-decimal 0x100-- - -Warning: imagecolorallocate(): Red component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Red component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Green component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Green component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Blue component is out of range in %s on line %d -bool(false) - -Warning: imagecolorallocate(): Blue component is out of range in %s on line %d -bool(false) +!! [Error] Red component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Red component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Green component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Green component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive) +!! [Error] Blue component is out of range, must be between 0 and 255 (inclusive) ===DONE===