diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 7f55b8bcc747..6a056287c451 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -3422,14 +3422,16 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode) im = php_gd_libgdimageptr_from_zval_p(IM); } + uint32_t ptsize_arg_num = mode == TTFTEXT_BBOX ? 1 : 2; + // FT_F26Dot6 is a signed long alias - if (ptsize < (double)LONG_MIN / 64 || ptsize > (double)LONG_MAX / 64) { - zend_argument_value_error(2, "must be between " ZEND_LONG_FMT " and " ZEND_LONG_FMT, (zend_long)((double)LONG_MIN / 64), (zend_long)((double)LONG_MAX / 64)); + if (ptsize < (double)LONG_MIN / 64 || ptsize >= (double)LONG_MAX / 64) { + zend_argument_value_error(ptsize_arg_num, "must be between " ZEND_LONG_FMT " and " ZEND_LONG_FMT, (zend_long)(LONG_MIN / 64), (zend_long)(LONG_MAX / 64)); RETURN_THROWS(); } if (UNEXPECTED(!zend_finite(ptsize))) { - zend_argument_value_error(2, "must be finite"); + zend_argument_value_error(ptsize_arg_num, "must be finite"); RETURN_THROWS(); } diff --git a/ext/gd/tests/gh18243.phpt b/ext/gd/tests/gh18243.phpt index 00698add614c..de0ac1861fb8 100644 --- a/ext/gd/tests/gh18243.phpt +++ b/ext/gd/tests/gh18243.phpt @@ -34,9 +34,16 @@ try { } catch (\ValueError $e) { echo $e::class, ': ', $e->getMessage(), PHP_EOL; } + +try { + imagettftext($im, 144115188075855872.0, 0, 15, 60, 0, $font, ""); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} ?> --EXPECTF-- ValueError: imagettftext(): Argument #2 ($size) must be between %i and %d ValueError: imagettftext(): Argument #2 ($size) must be between %i and %d ValueError: imagettftext(): Argument #2 ($size) must be finite ValueError: imagettftext(): Argument #2 ($size) must be between %i and %d +ValueError: imagettftext(): Argument #2 ($size) must be between %i and %d diff --git a/ext/gd/tests/imageftbbox_size_arg_num.phpt b/ext/gd/tests/imageftbbox_size_arg_num.phpt new file mode 100644 index 000000000000..b968817c48cf --- /dev/null +++ b/ext/gd/tests/imageftbbox_size_arg_num.phpt @@ -0,0 +1,62 @@ +--TEST-- +The $size errors name the argument of the function that was called +--EXTENSIONS-- +gd +--SKIPIF-- + +--FILE-- +getMessage(), "\n"; + } + try { + imagettfbbox($size, 0.0, $font, 'A'); + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; + } +} + +/* and argument #2 here */ +foreach ([NAN, INF] as $size) { + try { + imagefttext($image, $size, 0.0, 15, 60, 0, $font, 'A'); + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; + } + try { + imagettftext($image, $size, 0.0, 15, 60, 0, $font, 'A'); + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; + } +} + +/* the type error already agreed with the signature and still does */ +try { + imageftbbox('x', 0.0, $font, 'A'); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} +?> +--EXPECTF-- +ValueError: imageftbbox(): Argument #1 ($size) must be finite +ValueError: imagettfbbox(): Argument #1 ($size) must be finite +ValueError: imageftbbox(): Argument #1 ($size) must be between %i and %d +ValueError: imagettfbbox(): Argument #1 ($size) must be between %i and %d +ValueError: imageftbbox(): Argument #1 ($size) must be between %i and %d +ValueError: imagettfbbox(): Argument #1 ($size) must be between %i and %d +ValueError: imageftbbox(): Argument #1 ($size) must be between %i and %d +ValueError: imagettfbbox(): Argument #1 ($size) must be between %i and %d +ValueError: imagefttext(): Argument #2 ($size) must be finite +ValueError: imagettftext(): Argument #2 ($size) must be finite +ValueError: imagefttext(): Argument #2 ($size) must be between %i and %d +ValueError: imagettftext(): Argument #2 ($size) must be between %i and %d +TypeError: imageftbbox(): Argument #1 ($size) must be of type float, string given