From: e9925248 at stud4 dot tuwien dot ac dot at
Operating system: Windows 2000
PHP version: 4.3.2
PHP Bug Type: GD related
Bug description: Gif read support not thread safe

Description:
------------
If mod_php4 (precompiled from the web page), with php_gd2.dll extension
loaded, is used in Apache/1.3.27 on Windows 2000, createimagefromgif
returns black images or only parts of the image, if some pages call it at
the same time.

For example:
<?php
header ("Content-type: image/jpeg");
$im="image.gif";
$im1=imagecreatefromgif($im);
imagejpeg($im1);
?>
image.gif can be any gif, some KBs big.

Run in many terminal then something like
while /bin/true; do wget "http://server/skript.php"; done

only a part of the saved images will be ok. If only one images is fetched
at a time, all images are ok.

If the skript is used by many users, web browsers also show black images
or parts of the image.

I think, the error is in the bundled libgd, in gd_gif_in.c. There global
and static variables are used to read the gif, which all threads seem to
share. Removing them and storing them in a per Request state, seems to
solve the problem for me.

An example patch, which works for me, is at:
[url]http://stud4.tuwien.ac.at/~e9925248/php/gd-gif.diff[/url]

Martin Kögler
[email]e9925248stud4.tuwien.ac.at[/email]


Reproduce code:
---------------
<?php
header ("Content-type: image/jpeg");
$im="image.gif";
$im1=imagecreatefromgif($im);
imagejpeg($im1);
?>

Expected result:
----------------
The gif-image as jpeg

Actual result:
--------------
If some users use the script at the same time, the image has black parts.

--
Edit bug report at [url]http://bugs.php.net/?id=24844&edit=1[/url]
--
Try a CVS snapshot (php4): [url]http://bugs.php.net/fix.php?id=24844&r=trysnapshot4[/url]
Try a CVS snapshot (php5): [url]http://bugs.php.net/fix.php?id=24844&r=trysnapshot5[/url]
Fixed in CVS: [url]http://bugs.php.net/fix.php?id=24844&r=fixedcvs[/url]
Fixed in release: [url]http://bugs.php.net/fix.php?id=24844&r=alreadyfixed[/url]
Need backtrace: [url]http://bugs.php.net/fix.php?id=24844&r=needtrace[/url]
Try newer version: [url]http://bugs.php.net/fix.php?id=24844&r=oldversion[/url]
Not developer issue: [url]http://bugs.php.net/fix.php?id=24844&r=support[/url]
Expected behavior: [url]http://bugs.php.net/fix.php?id=24844&r=notwrong[/url]
Not enough info: [url]http://bugs.php.net/fix.php?id=24844&r=notenoughinfo[/url]
Submitted twice: [url]http://bugs.php.net/fix.php?id=24844&r=submittedtwice[/url]
register_globals: [url]http://bugs.php.net/fix.php?id=24844&r=globals[/url]
PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=24844&r=php3[/url]
Daylight Savings: [url]http://bugs.php.net/fix.php?id=24844&r=dst[/url]
IIS Stability: [url]http://bugs.php.net/fix.php?id=24844&r=isapi[/url]
Install GNU Sed: [url]http://bugs.php.net/fix.php?id=24844&r=gnused[/url]