PHP 4.0 Bug #4201: ImageCreateFromPNG("/dev/null") crashes (Segfault)
| From: | flebarbe at ocare dot com | Date: | Thu, 20 Apr 2000 17:26:27 +0000 |
| Subject: | PHP 4.0 Bug #4201: ImageCreateFromPNG("/dev/null") crashes (Segfault) | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-18061@lists.php.net to get a copy of this message | ||
From: flebarbe@ocare.com
Operating system: Linux
PHP version: 4.0 Latest CVS (20/04/2000)
PHP Bug Type: Reproduceable crash
Bug description: ImageCreateFromPNG("/dev/null") crashes (Segfault)
With gd and jpeg enabled in PHP4b4.
Here's a simple test script that crashes PHP4-cvs :
<?php
ImageCreateFromJPEG("/dev/null");
ImageCreateFromPNG("/dev/null");
?>
It crashes at shutdown time. I backtraced it to the
following :
(from gd.c, line 688) :
im = gdImageCreateFromJpeg(fp);
fflush(fp);
fclose(fp);
ZEND_REGISTER_RESOURCE(return_value, im, GDG(le_gd));
}
If gdImageCreateFromJpeg cannot interpret the file to
create the image, it returns NULL. So, NULL is registered
as a resource to free. Then, at shutdown time,
'gdImageDestroy' is called with NULL as argument, and
it crashes.
The patch I attach to this message does the folloing:
1) Issue a warning if gdImageCreateFromJPEG
returns NULL,
2) Returns false to the script (so that the programmer
can test it),
3) Prevents 'im' to be registered as a resource to destroy.
The situation is exactly the same for PNG and GIF.