pajoye          Fri Dec 16 19:02:07 2005 EDT

  Added files:                 
    /php-src/ext/gd/tests       copypalette.phpt createfromstring.phpt 
                                src.png 

  Modified files:              
    /php-src/ext/gd     gd.c 
  Log:
  - fix leaks and wrong error when invalid/empty string are given to
    imagecreatefromstring
  - add test for imagecreatefromstring
  - add test for palettecopy
  
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/gd.c?r1=1.326&r2=1.327&diff_format=u
Index: php-src/ext/gd/gd.c
diff -u php-src/ext/gd/gd.c:1.326 php-src/ext/gd/gd.c:1.327
--- php-src/ext/gd/gd.c:1.326   Fri Dec 16 17:02:30 2005
+++ php-src/ext/gd/gd.c Fri Dec 16 19:02:07 2005
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: gd.c,v 1.326 2005/12/16 17:02:30 pajoye Exp $ */
+/* $Id: gd.c,v 1.327 2005/12/16 19:02:07 pajoye Exp $ */
 
 /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
    Cold Spring Harbor Labs. */
@@ -1386,6 +1386,11 @@
        }
 
        convert_to_string_ex(data);
+       if (Z_STRLEN_PP(data) < 8) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string or 
invalid image");
+               RETURN_FALSE;
+       }
+
        memcpy(sig, Z_STRVAL_PP(data), 8);
 
        imtype = _php_image_type(sig);
@@ -1427,7 +1432,7 @@
                        break;
 
                default:
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Data is 
not in a recognized format.");
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Data is 
not in a recognized format");
                        RETURN_FALSE;
        }
 

http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/tests/copypalette.phpt?view=markup&rev=1.1
Index: php-src/ext/gd/tests/copypalette.phpt
+++ php-src/ext/gd/tests/copypalette.phpt
--TEST--
imagepalettecopy
--SKIPIF--
<?php
        if (!function_exists('imagecolorat')) die("skip gd extension not 
available\n");
?>
--FILE--
<?php
$im = imagecreate(1,1);
for ($i=0; $i<256; $i++) {
        imagecolorallocate($im, $i, $i, $i);
}

$im2 = imagecreate(1,1);
imagepalettecopy($im2, $im);

for ($i=0; $i<256; $i++) {
        $c = imagecolorsforindex($im2, $i);
        if ($c['red']!=$i || $c['green']!=$i || $c['blue']!=$i) {
                $failed = true;
                break;
        } 
}
echo "copy palette 255 colors: ";
echo $failed ? 'failed' : 'ok';
echo "\n";

$im = imagecreate(1,1);
$im2 = imagecreate(1,1);
imagecolorallocatealpha($im, 0,0,0,100);

imagepalettecopy($im2, $im);
$c = imagecolorsforindex($im2, 0);
if ($c['red']!=0 || $c['green']!=0 || $c['blue']!=0 || $c['alpha']!=100) {
        $failed = true;
} 
echo 'copy palette 1 color and alpha: ';
echo $failed ? 'failed' : 'ok';
echo "\n";
?>
--EXPECT--
copy palette 255 colors: ok
copy palette 1 color and alpha: ok

http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/tests/createfromstring.phpt?view=markup&rev=1.1
Index: php-src/ext/gd/tests/createfromstring.phpt
+++ php-src/ext/gd/tests/createfromstring.phpt
--TEST--
imagecreatefromstring
--SKIPIF--
<?php
        if (!function_exists('imagecreatefromstring')) die("skip gd extension 
not available\n");
?>
--FILE--
<?php
$dir = dirname(__FILE__);

$im = imagecreatetruecolor(5,5);
imagefill($im, 0,0, 0xffffff);
imagesetpixel($im, 3,3, 0x0);
imagepng($im, $dir . '/tc.png');

$im_string = file_get_contents(dirname(__FILE__) . '/tc.png');
$im = imagecreatefromstring($im_string);
echo 'createfromstring truecolor png: ';
if (imagecolorat($im, 3,3) != 0x0) {
        echo 'failed';
} else {
        echo 'ok';
}
echo "\n";
unlink($dir . '/tc.png');



$im = imagecreate(5,5);
$c1 = imagecolorallocate($im, 255,255,255);
$c2 = imagecolorallocate($im, 255,0,0);
imagefill($im, 0,0, $c1);
imagesetpixel($im, 3,3, $c2);
imagepng($im, $dir . '/p.png');

$im_string = file_get_contents(dirname(__FILE__) . '/p.png');
$im = imagecreatefromstring($im_string);

echo'createfromstring palette png: ';

$c = imagecolorsforindex($im, imagecolorat($im, 3,3));
$failed = false;
if ($c['red'] != 255 || $c['green'] != 0 || $c['blue'] != 0) {
        echo 'failed';
} else {
        echo 'ok';
}
echo "\n";
unlink($dir . '/p.png');


//empty string
$im = imagecreatefromstring('');
//random string > 8
$im = imagecreatefromstring(' asdf jklp');
?>
--EXPECTF--
createfromstring truecolor png: ok
createfromstring palette png: ok

Warning: imagecreatefromstring(): Empty string or invalid image in 
%screatefromstring.php on line %d

Warning: imagecreatefromstring(): Data is not in a recognized format in 
%screatefromstring.php on line %d

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to