php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19413 GD & freetype not thread safe
Submitted: 2002-09-15 01:34 UTC Modified: 2002-12-07 21:02 UTC
From: brianh at kheldar dot apana dot org dot au Assigned:
Status: Not a bug Package: GD related
PHP Version: 4.2.3 OS: OS/2
Private report: No CVE-ID: None
 [2002-09-15 01:34 UTC] brianh at kheldar dot apana dot org dot au
In testing Apache v2.0.40 running multi-threaded, I noticed regular exceptions occurring with concurrent requests for a GD generated image. I tracked it down to the fact that the way GD uses freetype is not thread safe (it uses a single static FT_Library object which the freetype docs specifically say shouldn't be shared between threads).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-15 01:53 UTC] brianh at kheldar dot apana dot org dot au
This patch serializes access to gdImageStringFT & friends, curing the segfaults I'd been getting.

http://silk.apana.org.au/pub/apache/gd_threadsafe_patch.txt
 [2002-09-15 03:13 UTC] derick@php.net
Setting this to critical so that it will be picked by somebody before 4.3 is released.

Derick
 [2002-09-16 15:27 UTC] rasmus@php.net
I really don't think an extension/library not being threadsafe is a critical issue for 4.3.  There are dozens of extensions with thread safety problems and if we say that making every extension threadsafe is a requirement for 4.3 it will take us 12+ months before we can release it.
 [2002-12-07 01:37 UTC] iliaa@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

PHP has no control over the Freetype library any thread safety issues should be addressed by the authors of that library.
 [2002-12-07 21:02 UTC] brianh at kheldar dot apana dot org dot au
>Sorry, but your problem does not imply a bug in PHP itself.

Well, that depends on whether you consider the bundled GD library to be part of "PHP itself". I believe the root of the problem is that GD (in gdft.c) uses static global variables:

static gdCache_head_t *fontCache;
static FT_Library library;

Both of these need to be thread local or their use serialized. The GD font cache code does no locking so sharing the font cache between threads is not safe. The FreeType docs also state that FT_Library objects should not be shared between threads.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 22:01:31 2024 UTC