php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24192 Unloading GD resource created with custom module causes crash
Submitted: 2003-06-15 10:12 UTC Modified: 2003-06-15 10:21 UTC
From: iridium at beyondunreal dot com Assigned:
Status: Not a bug Package: GD related
PHP Version: 4.3.2 OS: Windows XP sp1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: iridium at beyondunreal dot com
New email:
PHP Version: OS:

 

 [2003-06-15 10:12 UTC] iridium at beyondunreal dot com
Description:
------------
Apache Version: 1.3.27
Operating System: Windows XP SP1
PHP Version: 4.3.2

PHP runs as a module for apache.

Basically, I've created my own module for reading bitmaps under windows. The module creates a gd object, and reads the pixels from a bitmap to the gd object.

This module worked fine before PHP4.3.2 (at least it worked in 4.3.2's RCs), but it seems to have stopped working in PHP4.3.2's release.

What I did was I removed all of the code for creating the bitmap itself, and was left with the image creating code.

What I found was, that when the image was either destroyed, or unloaded, Apache Crashed ( presumably segmentation fault ).

As far as I can tell, I use exactly the same code as the gd module for creating an image.

I have included the code I use for my readbitmap function. I have tested le_gd and it is the correct value.

I'm afraid I cannot provide a backtrace because this is a windows system, and I am unfamilier with generating a backtrace on a windows system, and I could not see instruction on how to do it.

I tried compiling my module in debug mode, but when given the chance to debug when it crashed - I was given the ASM for apache, seeing as it was apache.exe that actually crashed, and apache was not compiled in debug mode.

I have also tried gdImageDestroy'ing (im) as soon as it is created and returning false. This does not cause any problems.

In the source below you can see im = readbitmaptogdimage(). This is the function that reads the bitmap, but it turns out that if I just use gdImageCreateTrueColor, when that is unloaded, apache crashes.

If you can think of anything that might cause it, or any way around the problem, it would be appreciated.

An alternative would be to write one function to get the size from a bitmap, create the image using php, and use another function to copy a bitmap to the image. If I try that, I'll reply to this bug report, but that should work, because the problem seems to be related to unloading resources created with a module.

I've written other modules that just manipulate gd resources (no resource creation), and they still work fine for PHP4.3.2.

Thanks in Advance for any help. Sorry I can't provide a backtrace..


Reproduce code:
---------------
PHP_FUNCTION(readbitmap)
{
	gdImagePtr im;
	zval **file;

	if ( zend_get_parameters_ex( 1, &file ) == FAILURE ) 
		ZEND_WRONG_PARAM_COUNT();

	convert_to_string_ex(file);
	//im = readbitmaptogdimage( Z_STRVAL_PP(file) );

	im = gdImageCreateTrueColor( 100, 100 );

	if ( !im ) RETURN_FALSE;

	ZEND_REGISTER_RESOURCE( return_value, im, le_gd );
}

Expected result:
----------------
A GD object to be created and registered as a resource

Actual result:
--------------
A GD object is created, but when an attempt is made to unload it (or when PHP finishes executing and does its resource cleanup), it crashes.

I cannot provide a backtrace at this time.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-15 10:18 UTC] stas@php.net
It might be helpful to explain what exactly is unloaded here and how. It may be that you are using some resource or function from unloaded DLL, in which case you should destroy the resources before unloading DLL.
 [2003-06-15 10:21 UTC] sniper@php.net
This bug system is not any support site, not for PHP script
or 3rd party extensions. Please ask such questions on more
appropriate forum, like internals@lists.php.net

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 15 05:01:31 2024 UTC