From: Mark Date: Tue, 3 Sep 2019 23:56:40 +0000 (+0200) Subject: Warnings to errors for imagecreatefromgd2part X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6c6c109e24531c777551cdc97501ace00c62d8ec;p=php Warnings to errors for imagecreatefromgd2part We also delete tests which were duplicates of a completely unrelated test. --- diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 83d5d1301a..3aead99242 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -1710,10 +1710,17 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, if (zend_parse_parameters(ZEND_NUM_ARGS(), "pllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) { return; } - if (width < 1 || height < 1) { - php_error_docref(NULL, E_WARNING, "Zero width or height not allowed"); - RETURN_FALSE; + + if (width < 1) { + zend_throw_error(NULL, "Width must be at least 1"); + return; } + + if (height < 1) { + zend_throw_error(NULL, "Height must be at least 1"); + return; + } + } else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &file, &file_len) == FAILURE) { return; diff --git a/ext/gd/tests/bug38212-mb.phpt b/ext/gd/tests/bug38212-mb.phpt index a7a3d65f13..9275a654db 100644 --- a/ext/gd/tests/bug38212-mb.phpt +++ b/ext/gd/tests/bug38212-mb.phpt @@ -6,12 +6,20 @@ Bug #38212 (Seg Fault on invalid imagecreatefromgd2part() parameters) ?> --FILE-- imagecreatefromgd2part($file, 0,0, -25, 10), + fn() => imagecreatefromgd2part($file, 0,0, 10, -25) +); + unlink($file); ?> ---EXPECTF-- -Warning: imagecreatefromgd2part(): Zero width or height not allowed in %s on line %d +--EXPECT-- +!! [Error] Width must be at least 1 +!! [Error] Height must be at least 1 diff --git a/ext/gd/tests/bug38212.phpt b/ext/gd/tests/bug38212.phpt index 039c6f971b..6d5c7e73d7 100644 --- a/ext/gd/tests/bug38212.phpt +++ b/ext/gd/tests/bug38212.phpt @@ -6,12 +6,20 @@ Bug #38212 (Seg Fault on invalid imagecreatefromgd2part() parameters) ?> --FILE-- imagecreatefromgd2part($file, 0,0, -25, 10), + fn() => imagecreatefromgd2part($file, 0,0, 10, -25) +); + unlink($file); ?> ---EXPECTF-- -Warning: imagecreatefromgd2part(): Zero width or height not allowed in %s on line %d +--EXPECT-- +!! [Error] Width must be at least 1 +!! [Error] Height must be at least 1 diff --git a/ext/gd/tests/bug39286-mb.phpt b/ext/gd/tests/bug39286-mb.phpt deleted file mode 100644 index 87390cb489..0000000000 --- a/ext/gd/tests/bug39286-mb.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Bug #39508 (imagefill crashes with small images 3 pixels or less) ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -Warning: imagecreatefromgd2part(): Zero width or height not allowed in %s on line %d diff --git a/ext/gd/tests/bug39286.phpt b/ext/gd/tests/bug39286.phpt deleted file mode 100644 index 4fe4769a7b..0000000000 --- a/ext/gd/tests/bug39286.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Bug #39508 (imagefill crashes with small images 3 pixels or less) ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -Warning: imagecreatefromgd2part(): Zero width or height not allowed in %s on line %d