Skip to content

imagettfbbox(): Could not find/open font UNC path #10344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JamesHeinrich opened this issue Jan 16, 2023 · 2 comments
Closed

imagettfbbox(): Could not find/open font UNC path #10344

JamesHeinrich opened this issue Jan 16, 2023 · 2 comments

Comments

@JamesHeinrich
Copy link

Description

imagettfbbox (possibly other TTF-related functions, I haven't tested) does not accept a UNC path to font file in PHP 8.2 on Windows 11. Code works as expected with local filename. Code worked fine with UNC path in PHP 7.4.1. UNC path/filename is accessible to user that Apache/PHP is running under (as shown in sample code).

The following code:

<?php
$font = '\\\\HOSTNAME\\path\\to\\arial.ttf'; // this file exists here, is readable to user PHP runs as
//$font = 'C:\\path\\to\\arial.ttf'; // this works
//$font = './arial.ttf'; // this works too, since font is in same folder as .php file
echo 'file_exists($font)='.(file_exists($font) ? 'TRUE' : 'FALSE').'<br>';
echo 'is_readable($font)='.(is_readable($font) ? 'TRUE' : 'FALSE').'<br>';
echo 'is_file($font)='    .(is_file($font)     ? 'TRUE' : 'FALSE').'<br>';
imagettfbbox(10, 0, $font, 'hello');

Resulted in this output:

file_exists($font)=TRUE
is_readable($font)=TRUE
is_file($font)=TRUE
E_WARNING: imagettfbbox(): Could not find/open font

But I expected this output instead:

file_exists($font)=TRUE
is_readable($font)=TRUE
is_file($font)=TRUE
// and no error message

PHP Version

PHP 8.2.0

Operating System

Windows 11 Pro x64

@mvorisek
Copy link
Contributor

It would be great to run all tests under UNC as pwd.

@nielsdos
Copy link
Member

I doubt this ever worked in the first place, but I do see what's wrong and might be able to fix it shortly.

@nielsdos nielsdos self-assigned this Jan 24, 2024
nielsdos added a commit to nielsdos/php-src that referenced this issue Jan 24, 2024
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.
nielsdos added a commit that referenced this issue Jan 25, 2024
* PHP-8.2:
  Fix GH-10344: imagettfbbox(): Could not find/open font UNC path
  Fix GH-13037: PharData incorrectly extracts zip file
nielsdos added a commit that referenced this issue Jan 25, 2024
* PHP-8.3:
  Fix GH-10344: imagettfbbox(): Could not find/open font UNC path
  Fix GH-13037: PharData incorrectly extracts zip file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants