From 311434a98eccb377fc0dcc2c47215045071f1c48 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Tue, 18 Aug 2026 08:01:46 +0200 Subject: [PATCH 1/3] ext/gd: name the real parameter in the imagecolormatch() size error The size-mismatch message cross-references argument #1 as $im1, a name the function lost in 14a26db3e2 when the ext/gd parameters were renamed for 8.0. Both parameters are $image1 and $image2. --- ext/gd/gd.c | 2 +- ext/gd/tests/imagecolormatch_error4.phpt | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 6a056287c451..7186c9e70230 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -785,7 +785,7 @@ PHP_FUNCTION(imagecolormatch) zend_argument_value_error(2, "must be Palette"); RETURN_THROWS(); case -3: - zend_argument_value_error(2, "must be the same size as argument #1 ($im1)"); + zend_argument_value_error(2, "must be the same size as argument #1 ($image1)"); RETURN_THROWS(); case -4: zend_argument_value_error(2, "must have at least one color"); diff --git a/ext/gd/tests/imagecolormatch_error4.phpt b/ext/gd/tests/imagecolormatch_error4.phpt index 2c117dcd46ab..4c3e11f4a6de 100644 --- a/ext/gd/tests/imagecolormatch_error4.phpt +++ b/ext/gd/tests/imagecolormatch_error4.phpt @@ -18,6 +18,13 @@ try { echo $exception::class, ': ', $exception->getMessage(), "\n"; } +/* the message names argument #1, so that name has to be the real one */ +foreach ((new ReflectionFunction('imagecolormatch'))->getParameters() as $parameter) { + echo '$', $parameter->getName(), "\n"; +} + ?> --EXPECT-- -ValueError: imagecolormatch(): Argument #2 ($image2) must be the same size as argument #1 ($im1) +ValueError: imagecolormatch(): Argument #2 ($image2) must be the same size as argument #1 ($image1) +$image1 +$image2 From 3b968a0adbd09fb7ff2230ae0c2f4b7355ed764a Mon Sep 17 00:00:00 2001 From: Louis-Arnaud Date: Fri, 4 Sep 2026 10:05:21 +0200 Subject: [PATCH 2/3] ext/gd: fix the wording of the imagejpeg() quality error The message read "must be at between -1 and 100". The sibling writers, imageavif() in particular, use the same bounds without the stray word. --- ext/gd/gd.c | 2 +- ext/gd/tests/imagejpeg_quality_range.phpt | 31 +++++++++++++++++++++++ ext/gd/tests/imageresolution_jpeg.phpt | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 ext/gd/tests/imagejpeg_quality_range.phpt diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 7186c9e70230..937a78e7e773 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -2114,7 +2114,7 @@ PHP_FUNCTION(imagejpeg) } if (quality < -1 || quality > 100) { - zend_argument_value_error(3, "must be at between -1 and 100"); + zend_argument_value_error(3, "must be between -1 and 100"); ctx->gd_free(ctx); RETURN_THROWS(); } diff --git a/ext/gd/tests/imagejpeg_quality_range.phpt b/ext/gd/tests/imagejpeg_quality_range.phpt new file mode 100644 index 000000000000..26a1dccc43f8 --- /dev/null +++ b/ext/gd/tests/imagejpeg_quality_range.phpt @@ -0,0 +1,31 @@ +--TEST-- +imagejpeg(): the accepted range of $quality and the message for values outside it +--EXTENSIONS-- +gd +--SKIPIF-- + +--FILE-- +getMessage(), PHP_EOL; + } +} +?> +--CLEAN-- + +--EXPECT-- +ValueError: imagejpeg(): Argument #3 ($quality) must be between -1 and 100 +bool(true) +bool(true) +bool(true) +ValueError: imagejpeg(): Argument #3 ($quality) must be between -1 and 100 diff --git a/ext/gd/tests/imageresolution_jpeg.phpt b/ext/gd/tests/imageresolution_jpeg.phpt index a918c7402d2c..fcca0f7f279f 100644 --- a/ext/gd/tests/imageresolution_jpeg.phpt +++ b/ext/gd/tests/imageresolution_jpeg.phpt @@ -43,7 +43,7 @@ array(2) { [1]=> int(299) } -ValueError: imagejpeg(): Argument #3 ($quality) must be at between -1 and 100 +ValueError: imagejpeg(): Argument #3 ($quality) must be between -1 and 100 --CLEAN-- Date: Fri, 4 Sep 2026 11:25:35 +0200 Subject: [PATCH 3/3] Update ext/gd/tests/imagejpeg_quality_range.phpt Co-authored-by: NickSdot <32384907+NickSdot@users.noreply.github.com> --- ext/gd/tests/imagejpeg_quality_range.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/gd/tests/imagejpeg_quality_range.phpt b/ext/gd/tests/imagejpeg_quality_range.phpt index 26a1dccc43f8..3a6aa292976e 100644 --- a/ext/gd/tests/imagejpeg_quality_range.phpt +++ b/ext/gd/tests/imagejpeg_quality_range.phpt @@ -14,8 +14,8 @@ $file = __DIR__ . '/imagejpeg_quality_range.jpeg'; foreach ([-2, -1, 0, 100, 101] as $quality) { try { var_dump(imagejpeg($image, $file, $quality)); - } catch (ValueError $e) { - echo $e::class, ': ', $e->getMessage(), PHP_EOL; + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } } ?>