php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27293 image2wbmp segfaults
Submitted: 2004-02-17 14:17 UTC Modified: 2004-02-21 11:41 UTC
From: nunoplopes at sapo dot pt Assigned:
Status: Closed Package: GD related
PHP Version: 5CVS OS: Win XP
Private report: No CVE-ID: None
 [2004-02-17 14:17 UTC] nunoplopes at sapo dot pt
Description:
------------
image2wbmp is segfaulting with my PHP 5.

Reproduce code:
---------------
<?php

$file = 'php.png';
$image = imagecreatefrompng($file);

header('Content-type: ' . image_type_to_mime_type(IMAGETYPE_WBMP));
image2wbmp($image);
?>

Expected result:
----------------
output the image

Actual result:
--------------
$ gdb php
GNU gdb 2003-09-20-cvs (cygwin-special)
(...)
(gdb) run bug.php
Starting program: /cygdrive/c/php/php.exe bug.php
---Type <return> to continue, or q <return> to quit---

Warning: image2wbmp(): Invalid threshold value '-1'. It must be between 0 and 25
5 in c:\nuno\testing\bug.php on line 7

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? () from
(gdb) bt
#0  0x00000000 in ?? () from

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-17 16:23 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2004-02-19 09:58 UTC] nlopess@php.net
Using latest snapshot, it doesn't segfault, but it generates a warning:
"Warning: image2wbmp(): Invalid threshold value '-1'. It must be between 0 and 255 in c:\nuno\testing\a.php on line 7"


----------
I'm not a developper, but I think this patch solves the problem:
cvs diff: Diffing .
Index: gd.c
===================================================================
RCS file: /repository/php-src/ext/gd/gd.c,v
retrieving revision 1.286
diff -u -r1.286 gd.c
--- gd.c        17 Feb 2004 21:30:00 -0000      1.286
+++ gd.c        19 Feb 2004 14:58:49 -0000
@@ -1682,7 +1682,7 @@
        char *fn = NULL;
        FILE *fp;
        int argc = ZEND_NUM_ARGS();
-       int q = -1, i, t = 1;
+       int q = 0, i, t = 1;

        /* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */
        /* When called from imagewbmp() the quality parameter stands for the for
eground color. Default: black. */
 [2004-02-19 19:24 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You need to pass threshold as the 3rd parameter to 
image2wbmp() function. 
 [2004-02-20 15:09 UTC] nlopess@php.net
from gc.c:

/* {{{ proto bool image2wbmp(resource im [, string filename [, int threshold]])
   Output WBMP image to browser or file */
PHP_FUNCTION(image2wbmp)


So thresold is optional.
 [2004-02-21 02:52 UTC] sniper@php.net
Not anymore.

 [2004-02-21 05:41 UTC] nlopess@php.net
Iliaa has already fixed the first part of the bug (segfaults), but the source needs another change.

The proto (and the documentation) state that the threshold is optional. And this is right.

If thresold wasn't optional, you should have to call this function like this:
image2wbmp($resource, '', 0);

It doesn't make any sense. Why not change the default value to a legal one? Please consider my patch.
 [2004-02-21 11:41 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC