Skip to content

Commit f698c62

Browse files
committed
Fix bug 64823: ZTS GD fails to to find system TrueType font
First, the `$fontfile` parameter actually supports a semicolon delimited list of fonts (as documented[1]); thus passing the full string to `VCWD_REALPATH()` or `php_check_open_basedir()` makes no sense; we could pass the individual parts, but … Second, libgd uses an elaborate font detection. There is a hard- coded `DEFAULT_PATH` which can be overridden by the environment variable `GDFONTPATH`. Semantics are like the `PATH` environment variable. If `DEFAULT_PATH` was still exposed (it is no longer as of libgd 2.1.0[2]), we could take that into account, but … External libgd can be configured with font-config support, so font aliases and even lookup patterns are supported. There is no way to cater to that upfront. Thus, we no longer interfere with libgd's font lookup. Checking the realpath was already doubtful (we didn't even use the resolved path). Lifting the open_basedir restriction is a bit more delicate, but the manual still states that open_basedir would not apply, and more relevant, not much harm can be done, because libgd only passes the found font to `FT_New_Face()` which likely fails for any non font files without any error which could reveal sensitive information. And the font file is never written. It should be noted that this solves lookup of system fonts, does not change the behavior for absolute font paths, but still does not resolve issues with relative paths to font files in ZTS environments using external libgd (our bundled libgd has a workaround for that). This particular issue cannot be solved, so users of ZTS builds still need to add `realpath(.)` to the `GDFONTPATH` as documented in the manual (or pass absolute paths as `$fontfile`). [1] <https://www.php.net/imagettftext> [2] <libgd/libgd@2a921c8> Closes GH-17366.
1 parent f2954bf commit f698c62

File tree

2 files changed

+1
-12
lines changed

2 files changed

+1
-12
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ PHP NEWS
3535
- GD:
3636
. Fixed bug #68629 (Transparent artifacts when using imagerotate). (pierre,
3737
cmb)
38+
. Fixed bug #64823 (ZTS GD fails to to find system TrueType font). (cmb)
3839

3940
- Intl:
4041
. Bumped ICU requirement to ICU >= 57.1. (cmb)

ext/gd/gd.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,18 +3374,6 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode)
33743374
}
33753375
}
33763376

3377-
#ifdef VIRTUAL_DIR
3378-
{
3379-
char tmp_font_path[MAXPATHLEN];
3380-
3381-
if (!VCWD_REALPATH(fontname, tmp_font_path)) {
3382-
fontname = NULL;
3383-
}
3384-
}
3385-
#endif /* VIRTUAL_DIR */
3386-
3387-
PHP_GD_CHECK_OPEN_BASEDIR(fontname, "Invalid font filename");
3388-
33893377
// libgd note: Those should return const char * ideally, but backward compatibility ..
33903378
if (EXT) {
33913379
error = gdImageStringFTEx(im, brect, col, fontname, ptsize, angle, x, y, str, &strex);

0 commit comments

Comments
 (0)