From: Nikita Popov Date: Wed, 2 Dec 2020 09:51:55 +0000 (+0100) Subject: Don't throw from imagecreatefromstring() with too short string X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a89aaf6c386679492e814cfbb5790142e29692fe;p=php 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. --- 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