|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14735 Missing function call in imagepsextendfont prevents multiple invocations
Submitted: 2001-12-28 10:52 UTC Modified: 2002-06-28 05:53 UTC
From: mfkahn2 at yahoo dot com Assigned:
Status: Closed Package: GD related
PHP Version: 4.1.0 OS: RH6.2
Private report: No CVE-ID: None
 [2001-12-28 10:52 UTC] mfkahn2 at yahoo dot com
The problem:  you can't call ImagePSExtendFont a second time after calling it once then calling ImagePSText.

To reproduce:
// ...
// $f holds a loaded font, $im holds a loaded image
// and $black and white hold allocated colours
header('Content-type: text/plain');

$b = ImagePSExtendFont($f,1);
echo "<!-- ImagePSExtendFont returned $b -->\n";
ImagePsText($im, "Hello", &$f, 20, $black, $white, rand(0,100),rand(0,0100));
$b = ImagePSExtendFont($f,1);
echo "<!-- ImagePSExtendFont returned $b -->\n";

// ...

The second echo of $b will show false.

I picked thru the t1lib code and found that the ImagePSText code is creating size-dependent data associated with the font, which will cause subsequent calls to ImagePSExtendFont to fail (actually the underlying t1lib call to T1_ExtendFont returns the OP_NOT_PERMITTED error (#12)).

To fix:
You need to call T1_DeleteAllSizes before calling T1_ExtendFont in the imagepsextendfont function in ext/gd/gd.c.  This removes all size-dependent data which prevents the T1_ExtendFont from succeeding the next time:

/* {{{ proto bool imagepsextendfont(int font_index, double extend)
   Extend or or condense (if extend < 1) a font */
        zval **fnt, **ext;
        int *f_ind;
        if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fnt, &ext) == FAILURE) {
        ZEND_FETCH_RESOURCE(f_ind, int *, fnt, -1, "Type 1 font", le_ps_font);
	/* !!! I added this line !!! */
        if (T1_ExtendFont(*f_ind, Z_DVAL_PP(ext)) != 0) RETURN_FALSE;
        php_error(E_WARNING, "ImagePsExtendFont: No T1lib support in this PHP build");
/* }}} */      
After I added the T1_DeleteAllSizes, it worked fine.  Also, memory consumption decreases since a bunch of bitmapped stuff gets freed up.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-28 05:53 UTC]
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at In case this was a documentation 
problem, the fix will show up soon at
In case this was a website problem, the change will show
up on the site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Dec 07 04:05:52 2022 UTC