]> granicus.if.org Git - php/commitdiff
Warnings to errors for imagecreatefromgd2part
authorMark <mrandall@digitellinc.com>
Tue, 3 Sep 2019 23:56:40 +0000 (01:56 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Wed, 4 Sep 2019 10:22:27 +0000 (12:22 +0200)
We also delete tests which were duplicates of a completely unrelated
test.

ext/gd/gd.c
ext/gd/tests/bug38212-mb.phpt
ext/gd/tests/bug38212.phpt
ext/gd/tests/bug39286-mb.phpt [deleted file]
ext/gd/tests/bug39286.phpt [deleted file]

index 83d5d1301a808ac4522c3c05d83a718d9764108e..3aead99242a59c3d2cf85237950d42ba5c805834 100644 (file)
@@ -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;
index a7a3d65f138ac839c652783c0be764147e4e259a..9275a654dbbe9e6c4162206d3d0e43294c2c70c1 100644 (file)
@@ -6,12 +6,20 @@ Bug #38212 (Seg Fault on invalid imagecreatefromgd2part() parameters)
 ?>
 --FILE--
 <?php
+require __DIR__ . '/func.inc';
+
 $file = __DIR__ . '/bug38212私はガラスを食べられます.gd2';
 $im1 = imagecreatetruecolor(10,100);
 imagefill($im1, 0,0, 0xffffff);
 imagegd2($im1, $file);
-$im = imagecreatefromgd2part($file, 0,0, -25,10);
+
+trycatch_dump(
+    fn() => 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
index 039c6f971ba0c8090856671688ba4f768aa8a038..6d5c7e73d7243317a3356680e9c4ebbc26c8d7fd 100644 (file)
@@ -6,12 +6,20 @@ Bug #38212 (Seg Fault on invalid imagecreatefromgd2part() parameters)
 ?>
 --FILE--
 <?php
+require __DIR__ . '/func.inc';
+
 $file = __DIR__ . '/bug38212.gd2';
 $im1 = imagecreatetruecolor(10,100);
 imagefill($im1, 0,0, 0xffffff);
 imagegd2($im1, $file);
-$im = imagecreatefromgd2part($file, 0,0, -25,10);
+
+trycatch_dump(
+    fn() => 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 (file)
index 87390cb..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
---TEST--
-Bug #39508 (imagefill crashes with small images 3 pixels or less)
---SKIPIF--
-<?php
-       if (!extension_loaded('gd')) die("skip gd extension not available\n");
-?>
---FILE--
-<?php
-$img =imagecreatefromgd2part("foo私はガラスを食べられます.png",0, 100, 0, 100);
-?>
---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 (file)
index 4fe4769..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
---TEST--
-Bug #39508 (imagefill crashes with small images 3 pixels or less)
---SKIPIF--
-<?php
-       if (!extension_loaded('gd')) die("skip gd extension not available\n");
-?>
---FILE--
-<?php
-$img =imagecreatefromgd2part("foo.png",0, 100, 0, 100);
-?>
---EXPECTF--
-Warning: imagecreatefromgd2part(): Zero width or height not allowed in %s on line %d