php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76160 Font not loaded if path holds semi collon
Submitted: 2018-03-29 09:48 UTC Modified: 2018-03-29 10:58 UTC
From: deepdiver at owncloud dot com Assigned: cmb (profile)
Status: Not a bug Package: GD related
PHP Version: Irrelevant OS: Debian Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: deepdiver at owncloud dot com
New email:
PHP Version: OS:

 

 [2018-03-29 09:48 UTC] deepdiver at owncloud dot com
Description:
------------
As soon as a semi-collon is in the path the font can no longer be loaded.

Tested with php 5.6 as well as php 7.2

Test script:
---------------
<?php

$fontFile = __DIR__ . '/fonts/foo;bar/OpenSans-Regular.ttf';
$image = imagecreate(128, 128);
$textColor = imagecolorallocate($image, 0, 0, 0);
imagettftext($image, 18, 0, 0, 0, $textColor, $fontFile, 'lorem');



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-29 09:58 UTC] spam2 at rhsoft dot net
don't get me wrong but using special chars in folder and filenames on webservers is in 2018 still dumb for the same reasons it was 1998 and that won't change in 2028 that much
 [2018-03-29 10:03 UTC] deepddiver at owncloud dot com
Well this is only the simplistic test code.

In real life I got hit by this in a continuous integration environment where the  semi colon was part of the root directory.
The root directory was computed based on ci config parameters which had the semi colon in place.

It took quite some time to find out about this .... unnecessarily

Never the less I'd expect that the given path is taken as is and not processed in a path list where the semi colon is used as separator..
 [2018-03-29 10:09 UTC] spam2 at rhsoft dot net
> The root directory was computed based on ci config 
> parameters which had the semi colon in place

well fix that crap, php runs on different operating systems and not all of them allows every char 


 static function NormalizeFilename(string $filename): string
 {
  static $allowed_chars;
  if(empty($allowed_chars))
  {
   $allowed_chars = array_flip(str_split('0123456789abcdefghijklmnopqrstuvwxyz_.-'));
  }
  $filename    = trim(strtolower($filename));
  $filename    = str_replace([chr(246),chr(214),chr(196),chr(228),chr(252),chr(220),chr(223)], ['oe','oe','ae','ae','ue','ue','ss'], $filename);
  $input_array = str_split(str_replace("\0", '', $filename));
  foreach($input_array as $key=>$char)
  {
   if(!isset($allowed_chars[$char]))
   {
    $input_array[$key] = '_';
   }
  }
  $filename = implode('', $input_array);
  while(strpos($filename, '..') !== false)
  {
   $filename = str_replace('..', '.', $filename);
  }
  while(strpos($filename, '__') !== false)
  {
   $filename = str_replace('__', '_', $filename);
  }
  $filename = str_replace('.php.', '.', $filename);
  return $filename;
 }
 [2018-03-29 10:14 UTC] deepdiver at owncloud dot com
<igony>Always a pleasure to see how polite and welcoming an open source community can be ...</igony>


I fixed that meanwhile ... still I consider this a bug.
 [2018-03-29 10:18 UTC] spam2 at rhsoft dot net
FWIW: i am just a user which wrote the function i posted 17 years ago by common sense in a world of networks with Windows, Apple and Linux machines 

it's enough that stupid users are using all sort of shiny special chars on SMB/AFP shares making migrations and exchange of files difficult but there is no reason do this serverside too
 [2018-03-29 10:58 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-03-29 10:58 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

A semicolon in the $fontfile parameter is used to separate
multiple paths (works like PATH_SEPARATOR, but it's always a
semicolon)[1].  If you want that to be changed, consider to file a
feature request for <https://github.com/libgd/libgd>, since that
would be an upstream issue.

[1] <http://www.php.net/manual/en/function.imagettftext.php#refsect1-function.imagettftext-parameters>
 [2018-03-30 03:03 UTC] a at b dot c dot de
Indeed, the path separator in GD Lib used to be a space in years past, but the only platform that didn't break on was DOS.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 10:01:29 2024 UTC