Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
7 changes: 7 additions & 0 deletions ext/gd/tests/gh18243.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
62 changes: 62 additions & 0 deletions ext/gd/tests/imageftbbox_size_arg_num.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--TEST--
The $size errors name the argument of the function that was called
--EXTENSIONS--
gd
--SKIPIF--
<?php
if (!function_exists('imageftbbox')) die('skip imageftbbox() not available');
?>
--FILE--
<?php
$font = __DIR__ . '/Rochester-Regular.otf';
$image = imagecreatetruecolor(100, 80);

/* $size is argument #1 here */
foreach ([NAN, INF, PHP_INT_MAX, PHP_INT_MIN] as $size) {
try {
imageftbbox($size, 0.0, $font, 'A');
} catch (Throwable $e) {
echo $e::class, ': ', $e->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
Loading