summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-12-02 10:51:55 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-12-02 10:51:55 +0100
commita89aaf6c386679492e814cfbb5790142e29692fe (patch)
treefbcdc8f33e07b02f77955bf9ece6e2b94f2f2f34
parent7a61984a2bf42f2632a8c62245a8496a3e2009cd (diff)
downloadphp-git-a89aaf6c386679492e814cfbb5790142e29692fe.tar.gz
Don't throw from imagecreatefromstring() with too short string
If the string is too short, we should treat this the same way as an unrecognized image type. This function should be usable to determine whether something is a valid image without doing any checks beforehand.
-rw-r--r--ext/gd/gd.c5
-rw-r--r--ext/gd/tests/createfromstring.phpt5
2 files changed, 6 insertions, 4 deletions
diff --git a/ext/gd/gd.c b/ext/gd/gd.c
index 88d04824ea..7a50fb423e 100644
--- a/ext/gd/gd.c
+++ b/ext/gd/gd.c
@@ -1483,8 +1483,9 @@ PHP_FUNCTION(imagecreatefromstring)
}
if (ZSTR_LEN(data) < sizeof(sig)) {
- zend_argument_value_error(1, "cannot be empty");
- RETURN_THROWS();
+ /* Handle this the same way as an unknown image type. */
+ php_error_docref(NULL, E_WARNING, "Data is not in a recognized format");
+ RETURN_FALSE;
}
memcpy(sig, ZSTR_VAL(data), sizeof(sig));
diff --git a/ext/gd/tests/createfromstring.phpt b/ext/gd/tests/createfromstring.phpt
index 6586d17c31..f3e40b26a9 100644
--- a/ext/gd/tests/createfromstring.phpt
+++ b/ext/gd/tests/createfromstring.phpt
@@ -62,6 +62,7 @@ $im = imagecreatefromstring(' asdf jklp foo');
--EXPECTF--
createfromstring truecolor png: ok
createfromstring palette png: ok
-imagecreatefromstring(): Argument #1 ($data) cannot be empty
-Warning: imagecreatefromstring(): Data is not in a recognized format in %screatefromstring.php on line %d
+Warning: imagecreatefromstring(): Data is not in a recognized format in %s on line %d
+
+Warning: imagecreatefromstring(): Data is not in a recognized format in %s on line %d