[php-src] PR #17366: Fix bug 64823: ZTS GD fails to to find system TrueType font
| From: | cmb69 | Date: | Sun, 05 Jan 2025 13:40:21 +0000 |
| Subject: | [php-src] PR #17366: Fix bug 64823: ZTS GD fails to to find system TrueType font | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-30257@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/17366
Author: cmb69
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] <https://github.com/libgd/libgd/commit/2a921c80fbdd1d684f32bf763c26e024052314e6>
---
Targeting master due to the removal of the open_basedir check.