diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 5bcf11846316..c5daf5f430f5 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -4014,10 +4014,14 @@ PHP_FUNCTION(imagecropauto) break; case GD_CROP_THRESHOLD: - if (color < 0 || (!gdImageTrueColor(im) && color >= gdImageColorsTotal(im))) { + if (color < 0) { zend_argument_value_error(4, "must be greater than or equal to 0 when using the threshold mode"); RETURN_THROWS(); } + if (!gdImageTrueColor(im) && color >= gdImageColorsTotal(im)) { + zend_argument_value_error(4, "must be a valid color index of the image when using the threshold mode"); + RETURN_THROWS(); + } im_crop = gdImageCropThreshold(im, color, (float) threshold); break; diff --git a/ext/gd/tests/bug72494.phpt b/ext/gd/tests/bug72494.phpt index 35e0359eae27..9e1b4cff65d3 100644 --- a/ext/gd/tests/bug72494.phpt +++ b/ext/gd/tests/bug72494.phpt @@ -14,4 +14,4 @@ trycatch_dump( ?> --EXPECT-- -!! [ValueError] imagecropauto(): Argument #4 ($color) must be greater than or equal to 0 when using the threshold mode +!! [ValueError] imagecropauto(): Argument #4 ($color) must be a valid color index of the image when using the threshold mode diff --git a/ext/gd/tests/imagecropauto_threshold_palette_color.phpt b/ext/gd/tests/imagecropauto_threshold_palette_color.phpt new file mode 100644 index 000000000000..dc06fe08be7b --- /dev/null +++ b/ext/gd/tests/imagecropauto_threshold_palette_color.phpt @@ -0,0 +1,21 @@ +--TEST-- +imagecropauto(): threshold mode, a color outside the palette +--EXTENSIONS-- +gd +--FILE-- +getMessage(), "\n"; + } +} +?> +--EXPECT-- +ValueError: imagecropauto(): Argument #4 ($color) must be a valid color index of the image when using the threshold mode +ValueError: imagecropauto(): Argument #4 ($color) must be greater than or equal to 0 when using the threshold mode +bool(true)