Skip to content

Commit 9f654de

Browse files
committed
Fix GH-20622: imagestring/imagestringup overflow/underflow.
close GH-20623
1 parent 77f2d12 commit 9f654de

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.3.30
44

5+
- GD:
6+
. Fixed bug GH-20622 (imagestring/imagestringup overflow). (David Carlier)
7+
58

69
18 Dec 2025, PHP 8.3.29
710

ext/gd/gd.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,7 +2763,8 @@ static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
27632763
char *C;
27642764
size_t C_len;
27652765
gdImagePtr im;
2766-
int ch = 0, col, x, y, i, l = 0;
2766+
int ch = 0, col, i, l = 0;
2767+
unsigned int x, y;
27672768
unsigned char *str = NULL;
27682769
zend_object *font_obj = NULL;
27692770
zend_long font_int = 0;
@@ -2795,21 +2796,21 @@ static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
27952796

27962797
switch (mode) {
27972798
case 0:
2798-
gdImageChar(im, font, x, y, ch, col);
2799+
gdImageChar(im, font, (int)x, (int)y, ch, col);
27992800
break;
28002801
case 1:
28012802
php_gdimagecharup(im, font, x, y, ch, col);
28022803
break;
28032804
case 2:
28042805
for (i = 0; (i < l); i++) {
2805-
gdImageChar(im, font, x, y, (int) ((unsigned char) str[i]), col);
2806+
gdImageChar(im, font, (int)x, (int)y, (int) ((unsigned char) str[i]), col);
28062807
x += font->w;
28072808
}
28082809
break;
28092810
case 3: {
28102811
for (i = 0; (i < l); i++) {
28112812
/* php_gdimagecharup(im, font, x, y, (int) str[i], col); */
2812-
gdImageCharUp(im, font, x, y, (int) str[i], col);
2813+
gdImageCharUp(im, font, (int)x, (int)y, (int) str[i], col);
28132814
y -= font->w;
28142815
}
28152816
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)