|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-07-23 12:01 UTC] k at ailis dot de
Description:
------------
imagecreatefromstring segfaults when using the external GD library. The bundled one works. As far as I understood this problem the imagecreatefromstring function calls gdNewDynamicCTX and this function frees some memory which don't have to be freed. Maybe this function was changed in the bundled GD library. But this is not needed. Instead of gdNewDynamicCtx the function gdNewDynamicCtxEx can be used. The additional third parameter must be 0 so the function doesn't free the memory. Doing in in that way imagecreatefromstring works again in the external GD library and also in the bundled one. Here is a small patch, but please take it with care. I don't really know what you are doing there with all these memory freeing hacks. Maybe my patch creates a memory leak. Don't know.
--- gd.c.orig 2004-07-23 11:24:51.000000000 +0200
+++ gd.c 2004-07-23 11:31:10.000000000 +0200
@@ -1274,7 +1274,7 @@
gdImagePtr im;
gdIOCtx *io_ctx;
- io_ctx = gdNewDynamicCtx (Z_STRLEN_PP(data), Z_STRVAL_PP(data));
+ io_ctx = gdNewDynamicCtxEx (Z_STRLEN_PP(data), Z_STRVAL_PP(data), 0);
if (!io_ctx) {
return NULL;
Reproduce code:
---------------
Can't provide one. The bug seems to be very system dependend. It works on some machines. On others it don't. It works for some image files. With others it don't.
Expected result:
----------------
No segfault.
Actual result:
--------------
segfault ;-)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 22:00:01 2025 UTC |
As of the next upload to the Debian archive, we will be using the following patch, which seems to clear up every php4-gd segfault bug we've had reported: --- php4-4.3.8/ext/gd/gd.c.orig 2004-07-24 06:00:25.000000000 -0600 +++ php4-4.3.8/ext/gd/gd.c 2004-07-24 06:10:38.000000000 -0600 @@ -1242,7 +1242,7 @@ #ifdef HAVE_GD_WBMP else { gdIOCtx *io_ctx; - io_ctx = gdNewDynamicCtx (8, data); + io_ctx = gdNewDynamicCtxEx (8, data, 0); if (io_ctx) { if (getmbi((int(*)(void*))gdGetC, io_ctx) == 0 && skipheader((int(*)(void*))gdGetC, io_ctx) == 0 ) { #if HAVE_LIBGD204 @@ -1274,7 +1274,7 @@ gdImagePtr im; gdIOCtx *io_ctx; - io_ctx = gdNewDynamicCtx (Z_STRLEN_PP(data), Z_STRVAL_PP(data)); + io_ctx = gdNewDynamicCtxEx (Z_STRLEN_PP(data), Z_STRVAL_PP(data), 0); if (!io_ctx) { return NULL; @@ -1428,7 +1428,7 @@ goto out_err; } - io_ctx = gdNewDynamicCtx(buff_size, buff); + io_ctx = gdNewDynamicCtxEx(buff_size, buff, 0); if(!io_ctx) { php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot allocate GD IO context"); goto out_err;Narf... This is NOT a bug in the GD library. The function you are using is freeing memory because this function is MEANT to do exactly this because this function normally deals with data which was allocated by GD itself. But you are passing data to this function which was allocated by YOU. Boutell has already dealt with this problem and has created new functions which exactly suit your needs: The gdImageCreateFrom*Ptr functions and also the gdNewDynamicCtxEx function. RTFM: * The new gdNewDynamicCtxEx function was added to support the easy implementation of the above functions and to correct a design problem which made life unpleasant for those passing in memory not originally allocated by gd to the gdNewDynamicCtx function by providing a way to specify that gd should never free or reallocate a particular block of memory. The gdNewDynamicCtx function and its relatives, although still exported for ABI compatibility, are now deprecated except for internal use, in favor of [45]gdImageCreateFromPngPtr and its relatives. So please stop putting your head in the sand and apply Adam Conrad's patch or move to the new gdImageCreateFrom*Ptr functions.