php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64822 imagettftext not closing font file handle
Submitted: 2013-05-12 12:39 UTC Modified: 2017-01-19 10:13 UTC
Votes:11
Avg. Score:4.3 ± 0.9
Reproduced:11 of 11 (100.0%)
Same Version:3 (27.3%)
Same OS:3 (27.3%)
From: amxmodx dot unloco at gmail dot com Assigned: cmb (profile)
Status: Closed Package: GD related
PHP Version: 5.4.4 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: amxmodx dot unloco at gmail dot com
New email:
PHP Version: OS:

 

 [2013-05-12 12:39 UTC] amxmodx dot unloco at gmail dot com
Description:
------------
after using imagettftext the font file handle is not closed which makes it 
impossible to rename/delete the font file without restarting Apache

$font = '../data/font/arruski.ttf';
$a = imagettftext($im, 20, 0, 10, 20, $white, $font, $text);

Using "Process Explorer" I was able to see that several font files are still open.
screenshot:http://i44.tinypic.com/2iubwu8.png


Test script:
---------------
	header('Content-Type: image/png');
	$im = imagecreatetruecolor(400, 30);

	$white = imagecolorallocate($im, 255, 255, 255);
	$text = 'Test';
	$font = '../data/font/arruski.ttf';
	$a = imagettftext($im, 20, 0, 10, 20, $white, $font, $text);
	$fp = fopen($font,'r');
	fclose($fp);
	imagepng($im);
	imagedestroy($im);


Expected result:
----------------
the font file would be released after script execution

Actual result:
--------------
the font file is not released.
"The action can't be completed because the file is open in httpd.exe"
Users cannot replace/rename/delete font file !

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-05-12 12:46 UTC] amxmodx dot unloco at gmail dot com
-Operating System: win8 +Operating System: win8 32bit -PHP Version: 5.4.15 +PHP Version: 5.4.4
 [2013-05-12 12:46 UTC] amxmodx dot unloco at gmail dot com
PHP v5.4.4
 [2015-05-17 16:43 UTC] rjbaytos at rjbaytos dot ddns dot net
I was able to reproduce this bug. It's a hassle when trying to replace or move the ttf files around. The only solution so far is to restart the server.
    <?php
    if (isset($_GET['METHOD']) && $_GET['METHOD']=='captcha')
    {   session_start();
        $code=rand(1000,9999);
        $_SESSION["code"] = $code;
        session_write_close();
        $font = rand(1,4).".ttf";
        if ($font == "1.ttf")
            $font_size = 20;
        else if ($font == "2.ttf")
            $font_size = 25;
        else if ($font == "3.ttf")
            $font_size = 30;
        else if ($font == "4.ttf")
            $font_size = 35;
        $angle = 0;
        $width = 120;
        $height = 60;
        $bounding_box = imagettfbbox($font_size, $angle, $font, $code);
        $textwidth = abs($bounding_box[4] - $bounding_box[0]);
        $textheight = abs($bounding_box[5] - $bounding_box[1]);
        $x = ($width - $textwidth) / 2;
        $y = (($height*3/4) + $textheight) / 2;
        $image = imagecreatetruecolor($width, $height);
        $text_background = imagecolorallocate($image, 0, 0, 0);
        $color = imagecolorallocate($image, 230, 230, 230);
        imagefill($image, 0, 0, $text_background);
        imageline($image, 0, $y-rand(0,10), $width, $y-rand(0,10), $color);
        imageline($image, 0, $y, $width, $y, $color);
        imageline($image, 0, $y+rand(0,10), $width, $y-rand(0,20), $color);
        imageline($image, $x+rand(0,$width/2), 0, $x+rand($width/2,$width), $height, $color);
        imageline($image, $x+rand(0,$width/2), $height, $x+rand($width/2,$width), 0, $color);
        for($i=0;$i<400;$i++)
        {   imagesetpixel($image,rand()%$width,rand()%$height,$color);
        }
        imagettftext($image, $font_size, $angle, $x, $y, $color, $font, $code);
        header("Cache-Control: no-cache, must-revalidate");
        header('Content-type: image/png');
        imagepng($image);
        imagedestroy($image);
        exit();
    }
    ?>
    <img src = "<?php echo $_SERVER['PHP_SELF']; ?>?METHOD=captcha">
 [2017-01-18 18:28 UTC] cmb@php.net
-Status: Open +Status: Feedback -Operating System: win8 32bit +Operating System: Windows -Assigned To: +Assigned To: cmb
 [2017-01-18 18:28 UTC] cmb@php.net
I can reproduce this with PHP 5.4, but neither with 5.6 nor 7.0.
Can you confirm?
 [2017-01-19 08:13 UTC] amxmodx dot unloco at gmail dot com
-Status: Feedback +Status: Assigned
 [2017-01-19 08:13 UTC] amxmodx dot unloco at gmail dot com
I confirm that it's no longer bugged in 5.5.12, 
I will guess it's also resolved in 5.6 & 7
 [2017-01-19 10:13 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 [2017-01-19 10:13 UTC] cmb@php.net
Thanks for the confirmation. I'm closing this ticket. Please
re-open if it turns out that there are still issues with newer
PHP/GD versions.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 27 16:01:27 2024 UTC