From 1024844a41a4a3934ff234bcaab89b8fb8b0bf4e Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Sat, 17 Dec 2005 17:46:59 +0000 Subject: [PATCH] - MFH: - fix leaks and wrong error when invalid/empty string are given to imagecreatefromstring - add test for imagecreatefromstring - add test for palettecopy --- ext/gd/gd.c | 7 +++- ext/gd/tests/copypalette.phpt | 43 ++++++++++++++++++++ ext/gd/tests/createfromstring.phpt | 63 +++++++++++++++++++++++++++++ ext/gd/tests/src.png | Bin 0 -> 9 bytes 4 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 ext/gd/tests/copypalette.phpt create mode 100644 ext/gd/tests/createfromstring.phpt create mode 100644 ext/gd/tests/src.png diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 30acee57e6..5fe9ecdfcc 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -1429,6 +1429,11 @@ PHP_FUNCTION(imagecreatefromstring) } 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); @@ -1480,7 +1485,7 @@ PHP_FUNCTION(imagecreatefromstring) 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; } diff --git a/ext/gd/tests/copypalette.phpt b/ext/gd/tests/copypalette.phpt new file mode 100644 index 0000000000..2962455b65 --- /dev/null +++ b/ext/gd/tests/copypalette.phpt @@ -0,0 +1,43 @@ +--TEST-- +imagepalettecopy +--SKIPIF-- + +--FILE-- + +--EXPECT-- +copy palette 255 colors: ok +copy palette 1 color and alpha: ok diff --git a/ext/gd/tests/createfromstring.phpt b/ext/gd/tests/createfromstring.phpt new file mode 100644 index 0000000000..b3d7dde157 --- /dev/null +++ b/ext/gd/tests/createfromstring.phpt @@ -0,0 +1,63 @@ +--TEST-- +imagecreatefromstring +--SKIPIF-- + +--FILE-- + 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 diff --git a/ext/gd/tests/src.png b/ext/gd/tests/src.png new file mode 100644 index 0000000000000000000000000000000000000000..d38c74268a0f8235927e436cfb163175bb68b7ea GIT binary patch literal 9 QcmZQzU}gRB