Skip to content

Commit 4a48729

Browse files
committed
Fix phpGH-10344: imagettfbbox(): Could not find/open font UNC path
libgd uses an incorrect absolute path check in gdft.c. It checks if either the path starts with a '/' (only valid on Posix btw), or whether it contains something of the form C:\ or C:/. However, this overlooks the possibility of using UNC paths on Windows. As we already do PHP-specific stuff with VCWD_ macros, use IS_ABSOLUTE_PATH to check for an absolute path which will take into account UNC paths as well. Closes phpGH-13241.
1 parent ba80372 commit 4a48729

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ PHP NEWS
1616
. Fixed bug GH-12996 (Incorrect SCRIPT_NAME with Apache ProxyPassMatch when
1717
plus in path). (Jakub Zelenka)
1818

19+
- GD:
20+
. Fixed bug GH-10344 (imagettfbbox(): Could not find/open font UNC path).
21+
(nielsdos)
22+
1923
- MySQLnd:
2024
. Fixed bug GH-12107 (When running a stored procedure (that returns a result
2125
set) twice, PHP crashes). (nielsdos)

ext/gd/libgd/gdft.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,17 @@ static void *fontFetch (char **error, void *key)
401401
#ifdef NETWARE
402402
if (*name == '/' || (name[0] != 0 && strstr(name, ":/"))) {
403403
#else
404-
if (*name == '/' || (name[0] != 0 && name[1] == ':' && (name[2] == '/' || name[2] == '\\'))) {
404+
/* Actual length doesn't matter, just the minimum does up to length 2. */
405+
unsigned int min_length = 0;
406+
if (name[0] != '\0') {
407+
if (name[1] != '\0') {
408+
min_length = 2;
409+
} else {
410+
min_length = 1;
411+
}
412+
}
413+
ZEND_IGNORE_VALUE(min_length); /* On Posix systems this may be unused */
414+
if (IS_ABSOLUTE_PATH(name, min_length)) {
405415
#endif
406416
snprintf(fullname, sizeof(fullname) - 1, "%s", name);
407417
if (access(fullname, R_OK) == 0) {

ext/gd/tests/gh10344.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
GH-10344 (imagettfbbox(): Could not find/open font UNC path)
3+
--EXTENSIONS--
4+
gd
5+
--SKIPIF--
6+
<?php
7+
if (PHP_OS_FAMILY != 'Windows') {
8+
die("skip windows only test");
9+
}
10+
if (!GD_BUNDLED) {
11+
die("skip Not (yet) fixed in libgd itself");
12+
}
13+
if (!function_exists("imagettfbbox")) {
14+
die("skip ttf support unavailable");
15+
}
16+
if (!is_readable("\\\\localhost\\c$\\Windows\\Fonts\\arial.ttf")) {
17+
die("skip font not readable");
18+
}
19+
?>
20+
--FILE--
21+
<?php
22+
23+
$font = '\\\\localhost\\c$\\Windows\\Fonts\\arial.ttf';
24+
var_dump(count(imagettfbbox(10, 0, $font, 'hello')));
25+
26+
?>
27+
--EXPECT--
28+
int(8)

0 commit comments

Comments
 (0)