Skip to content

Commit 6c6c109

Browse files
marandallcmb69
authored andcommitted
Warnings to errors for imagecreatefromgd2part
We also delete tests which were duplicates of a completely unrelated test.
1 parent 6a05e42 commit 6c6c109

File tree

5 files changed

+32
-33
lines changed

5 files changed

+32
-33
lines changed

ext/gd/gd.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,10 +1710,17 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
17101710
if (zend_parse_parameters(ZEND_NUM_ARGS(), "pllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
17111711
return;
17121712
}
1713-
if (width < 1 || height < 1) {
1714-
php_error_docref(NULL, E_WARNING, "Zero width or height not allowed");
1715-
RETURN_FALSE;
1713+
1714+
if (width < 1) {
1715+
zend_throw_error(NULL, "Width must be at least 1");
1716+
return;
17161717
}
1718+
1719+
if (height < 1) {
1720+
zend_throw_error(NULL, "Height must be at least 1");
1721+
return;
1722+
}
1723+
17171724
} else {
17181725
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &file, &file_len) == FAILURE) {
17191726
return;

ext/gd/tests/bug38212-mb.phpt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ Bug #38212 (Seg Fault on invalid imagecreatefromgd2part() parameters)
66
?>
77
--FILE--
88
<?php
9+
require __DIR__ . '/func.inc';
10+
911
$file = __DIR__ . '/bug38212私はガラスを食べられます.gd2';
1012
$im1 = imagecreatetruecolor(10,100);
1113
imagefill($im1, 0,0, 0xffffff);
1214
imagegd2($im1, $file);
13-
$im = imagecreatefromgd2part($file, 0,0, -25,10);
15+
16+
trycatch_dump(
17+
fn() => imagecreatefromgd2part($file, 0,0, -25, 10),
18+
fn() => imagecreatefromgd2part($file, 0,0, 10, -25)
19+
);
20+
1421
unlink($file);
1522
?>
16-
--EXPECTF--
17-
Warning: imagecreatefromgd2part(): Zero width or height not allowed in %s on line %d
23+
--EXPECT--
24+
!! [Error] Width must be at least 1
25+
!! [Error] Height must be at least 1

ext/gd/tests/bug38212.phpt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ Bug #38212 (Seg Fault on invalid imagecreatefromgd2part() parameters)
66
?>
77
--FILE--
88
<?php
9+
require __DIR__ . '/func.inc';
10+
911
$file = __DIR__ . '/bug38212.gd2';
1012
$im1 = imagecreatetruecolor(10,100);
1113
imagefill($im1, 0,0, 0xffffff);
1214
imagegd2($im1, $file);
13-
$im = imagecreatefromgd2part($file, 0,0, -25,10);
15+
16+
trycatch_dump(
17+
fn() => imagecreatefromgd2part($file, 0,0, -25, 10),
18+
fn() => imagecreatefromgd2part($file, 0,0, 10, -25)
19+
);
20+
1421
unlink($file);
1522
?>
16-
--EXPECTF--
17-
Warning: imagecreatefromgd2part(): Zero width or height not allowed in %s on line %d
23+
--EXPECT--
24+
!! [Error] Width must be at least 1
25+
!! [Error] Height must be at least 1

ext/gd/tests/bug39286-mb.phpt

Lines changed: 0 additions & 12 deletions
This file was deleted.

ext/gd/tests/bug39286.phpt

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)