Bug #64822 [Asn->Csd]: imagettftext not closing font file handle

From: Date: Thu, 19 Jan 2017 10:13:11 +0000
Subject: Bug #64822 [Asn->Csd]: imagettftext not closing font file handle
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206740@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64822&edit=1 ID: 64822 Updated by: cmb@php.net Reported by: amxmodx dot unloco at gmail dot com Summary: imagettftext not closing font file handle -Status: Assigned +Status: Closed Type: Bug Package: GD related Operating System: Windows PHP Version: 5.4.4 Assigned To: cmb Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2017-01-19 08:13:59] 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-18 18:28:29] cmb@php.net I can reproduce this with PHP 5.4, but neither with 5.6 nor 7.0. Can you confirm? ------------------------------------------------------------------------ [2015-05-17 16:43:33] 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"> ------------------------------------------------------------------------ [2013-05-12 12:46:47] amxmodx dot unloco at gmail dot com PHP v5.4.4 ------------------------------------------------------------------------ [2013-05-12 12:39:05] 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 ! ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64822&edit=1

« previous php.bugs (#206740) next »