Skip to content

Commit 1e464e5

Browse files
committed
ext/gd: Fix GH-13082
Issue occur when compiling with recent clang releases (> 13) and with the '-Os' optimisation level, after using `imageloadfont` which returns a proper GdFont class leads to a subtle bug when attempting to use via the imagefont* function.
1 parent 6339938 commit 1e464e5

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ PHP NEWS
2525
(Jakub Zelenka)
2626
. Fixed bug GH-12905 (FFI::new interacts badly with observers). (nielsdos)
2727

28+
- GD:
29+
. Fixed GH-13082 undefined behavior with GdFont instances handling with
30+
imageload* and imagechar*. (David Carlier)
31+
2832
- Intl:
2933
. Fixed GH-12943 (IntlDateFormatter::__construct accepts 'C' as valid locale).
3034
(David Carlier)

ext/gd/gd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,8 +2681,8 @@ static gdFontPtr php_find_gd_font(zend_object *font_obj, zend_long font_int)
26812681
*/
26822682
static void php_imagefontsize(INTERNAL_FUNCTION_PARAMETERS, int arg)
26832683
{
2684-
zend_object *font_obj;
2685-
zend_long font_int;
2684+
zend_object *font_obj = NULL;
2685+
zend_long font_int = 0;
26862686
gdFontPtr font;
26872687

26882688
ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -2750,8 +2750,8 @@ static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
27502750
int ch = 0, col, x, y, i, l = 0;
27512751
unsigned char *str = NULL;
27522752
zend_object *font_obj;
2753-
zend_long font_int;
2754-
gdFontPtr font;
2753+
zend_long font_int = 0;
2754+
gdFontPtr font = NULL;
27552755

27562756
ZEND_PARSE_PARAMETERS_START(6, 6)
27572757
Z_PARAM_OBJECT_OF_CLASS(IM, gd_image_ce)

ext/gd/tests/gh13082.gdf

52.5 KB
Binary file not shown.

ext/gd/tests/gh13082.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-13082 - imagefontwidth/height unexpectedly throwing an exception on a valid GdFont object.
3+
--EXTENSIONS--
4+
gd
5+
--FILE--
6+
<?php
7+
$font = imageloadfont(__DIR__ . "/gh13082.gdf");
8+
if ($font === false) die("imageloadfont failed");
9+
if (!($font instanceof GdFont)) die("invalid gd font");
10+
11+
var_dump(imagefontwidth($font));
12+
var_dump(imagefontheight($font));
13+
?>
14+
--EXPECT--
15+
int(12)
16+
int(20)

0 commit comments

Comments
 (0)