Skip to content

Commit abf6f8b

Browse files
committedApr 5, 2025
Merge branch 'PHP-8.4'
2 parents 462b170 + 471995c commit abf6f8b

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
 

‎ext/gd/gd.c

+11
Original file line numberDiff line numberDiff line change
@@ -3363,6 +3363,17 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode)
33633363
im = php_gd_libgdimageptr_from_zval_p(IM);
33643364
}
33653365

3366+
// FT_F26Dot6 is a signed long alias
3367+
if (ptsize < (double)LONG_MIN / 64 || ptsize > (double)LONG_MAX / 64) {
3368+
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));
3369+
RETURN_THROWS();
3370+
}
3371+
3372+
if (UNEXPECTED(!zend_finite(ptsize))) {
3373+
zend_argument_value_error(2, "must be finite");
3374+
RETURN_THROWS();
3375+
}
3376+
33663377
/* convert angle to radians */
33673378
angle = angle * (M_PI/180);
33683379

‎ext/gd/tests/gh18243.phpt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
GH-18243: imagefttext underflow/overflow on $size
3+
--EXTENSIONS--
4+
gd
5+
--SKIPIF--
6+
<?php
7+
if(!function_exists('imagettftext')) die('skip imagettftext() not available');
8+
?>
9+
--FILE--
10+
<?php
11+
$font = __DIR__.'/Rochester-Regular.otf';
12+
$im = imagecreatetruecolor(100, 80);
13+
14+
try {
15+
imagettftext($im, PHP_INT_MAX, 0, 15, 60, 0, $font, "");
16+
} catch (\ValueError $e) {
17+
echo $e->getMessage(), PHP_EOL;
18+
}
19+
20+
try {
21+
imagettftext($im, PHP_INT_MIN, 0, 15, 60, 0, $font, "");
22+
} catch (\ValueError $e) {
23+
echo $e->getMessage(), PHP_EOL;
24+
}
25+
26+
try {
27+
imagettftext($im, NAN, 0, 15, 60, 0, $font, "");
28+
} catch (\ValueError $e) {
29+
echo $e->getMessage(), PHP_EOL;
30+
}
31+
32+
try {
33+
imagettftext($im, INF, 0, 15, 60, 0, $font, "");
34+
} catch (\ValueError $e) {
35+
echo $e->getMessage();
36+
}
37+
?>
38+
--EXPECTF--
39+
imagettftext(): Argument #2 ($size) must be between %i and %d
40+
imagettftext(): Argument #2 ($size) must be between %i and %d
41+
imagettftext(): Argument #2 ($size) must be finite
42+
imagettftext(): Argument #2 ($size) must be between %i and %d

0 commit comments

Comments
 (0)
Please sign in to comment.