Skip to content

Commit 8504b18

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-20622: imagestring/imagestringup overflow/underflow.
2 parents fc592c7 + 400aa84 commit 8504b18

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

ext/gd/gd.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,7 +2976,8 @@ static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
29762976
zend_long X, Y, COL;
29772977
zend_string *C;
29782978
gdImagePtr im;
2979-
int ch = 0, col, x, y, i;
2979+
int ch = 0, col, i, l = 0;
2980+
unsigned int x, y;
29802981
size_t l = 0;
29812982
unsigned char *str = NULL;
29822983
zend_object *font_obj = NULL;
@@ -3009,21 +3010,21 @@ static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
30093010

30103011
switch (mode) {
30113012
case 0:
3012-
gdImageChar(im, font, x, y, ch, col);
3013+
gdImageChar(im, font, (int)x, (int)y, ch, col);
30133014
break;
30143015
case 1:
30153016
php_gdimagecharup(im, font, x, y, ch, col);
30163017
break;
30173018
case 2:
30183019
for (i = 0; (i < l); i++) {
3019-
gdImageChar(im, font, x, y, (int) ((unsigned char) str[i]), col);
3020+
gdImageChar(im, font, (int)x, (int)y, (int) ((unsigned char) str[i]), col);
30203021
x += font->w;
30213022
}
30223023
break;
30233024
case 3: {
30243025
for (i = 0; (i < l); i++) {
30253026
/* php_gdimagecharup(im, font, x, y, (int) str[i], col); */
3026-
gdImageCharUp(im, font, x, y, (int) str[i], col);
3027+
gdImageCharUp(im, font, (int)x, (int)y, (int) str[i], col);
30273028
y -= font->w;
30283029
}
30293030
break;

ext/gd/tests/gh20622.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
GH-20622 (imagestring/imagestringup overflow/underflow)
3+
--EXTENSIONS--
4+
gd
5+
--FILE--
6+
<?php
7+
$im = imagecreate(64, 64);
8+
imagestringup($im, 5, 0, -2147483648, 'STRINGUP', 0);
9+
imagestring($im, 5, -2147483648, 0, 'STRING', 0);
10+
echo "OK";
11+
?>
12+
--EXPECT--
13+
OK

0 commit comments

Comments
 (0)