Skip to content

Commit 5f0cd02

Browse files
committed
ext/gd: report $size with the argument number of the function called
php_imagettftext_common() serves the bbox functions, where $size is argument #1, and the drawing ones, where it is #2, but its two size checks hardcode 2. imageftbbox(NAN, ...) therefore blamed $angle.
1 parent 78c33e0 commit 5f0cd02

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

ext/gd/gd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,14 +3422,16 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode)
34223422
im = php_gd_libgdimageptr_from_zval_p(IM);
34233423
}
34243424

3425+
uint32_t ptsize_arg_num = mode == TTFTEXT_BBOX ? 1 : 2;
3426+
34253427
// FT_F26Dot6 is a signed long alias
34263428
if (ptsize < (double)LONG_MIN / 64 || ptsize > (double)LONG_MAX / 64) {
3427-
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));
3429+
zend_argument_value_error(ptsize_arg_num, "must be between " ZEND_LONG_FMT " and " ZEND_LONG_FMT, (zend_long)((double)LONG_MIN / 64), (zend_long)((double)LONG_MAX / 64));
34283430
RETURN_THROWS();
34293431
}
34303432

34313433
if (UNEXPECTED(!zend_finite(ptsize))) {
3432-
zend_argument_value_error(2, "must be finite");
3434+
zend_argument_value_error(ptsize_arg_num, "must be finite");
34333435
RETURN_THROWS();
34343436
}
34353437

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
The $size errors name the argument of the function that was called
3+
--EXTENSIONS--
4+
gd
5+
--SKIPIF--
6+
<?php
7+
if (!function_exists('imageftbbox')) die('skip imageftbbox() not available');
8+
?>
9+
--FILE--
10+
<?php
11+
$font = __DIR__ . '/Rochester-Regular.otf';
12+
$image = imagecreatetruecolor(100, 80);
13+
14+
/* $size is argument #1 here */
15+
foreach ([NAN, INF, PHP_INT_MAX, PHP_INT_MIN] as $size) {
16+
try {
17+
imageftbbox($size, 0.0, $font, 'A');
18+
} catch (ValueError $e) {
19+
echo $e->getMessage(), "\n";
20+
}
21+
try {
22+
imagettfbbox($size, 0.0, $font, 'A');
23+
} catch (ValueError $e) {
24+
echo $e->getMessage(), "\n";
25+
}
26+
}
27+
28+
/* and argument #2 here */
29+
foreach ([NAN, INF] as $size) {
30+
try {
31+
imagefttext($image, $size, 0.0, 15, 60, 0, $font, 'A');
32+
} catch (ValueError $e) {
33+
echo $e->getMessage(), "\n";
34+
}
35+
try {
36+
imagettftext($image, $size, 0.0, 15, 60, 0, $font, 'A');
37+
} catch (ValueError $e) {
38+
echo $e->getMessage(), "\n";
39+
}
40+
}
41+
42+
/* the type error already agreed with the signature and still does */
43+
try {
44+
imageftbbox('x', 0.0, $font, 'A');
45+
} catch (TypeError $e) {
46+
echo $e->getMessage(), "\n";
47+
}
48+
?>
49+
--EXPECTF--
50+
imageftbbox(): Argument #1 ($size) must be finite
51+
imagettfbbox(): Argument #1 ($size) must be finite
52+
imageftbbox(): Argument #1 ($size) must be between %i and %d
53+
imagettfbbox(): Argument #1 ($size) must be between %i and %d
54+
imageftbbox(): Argument #1 ($size) must be between %i and %d
55+
imagettfbbox(): Argument #1 ($size) must be between %i and %d
56+
imageftbbox(): Argument #1 ($size) must be between %i and %d
57+
imagettfbbox(): Argument #1 ($size) must be between %i and %d
58+
imagefttext(): Argument #2 ($size) must be finite
59+
imagettftext(): Argument #2 ($size) must be finite
60+
imagefttext(): Argument #2 ($size) must be between %i and %d
61+
imagettftext(): Argument #2 ($size) must be between %i and %d
62+
imageftbbox(): Argument #1 ($size) must be of type float, string given

0 commit comments

Comments
 (0)