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.
This commit is contained in:
Nikita Popov 2020-12-02 10:51:55 +01:00
parent 7a61984a2b
commit a89aaf6c38
2 changed files with 6 additions and 4 deletions

View file

@ -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));

View file

@ -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