Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,12 +693,12 @@ PHP_FUNCTION(imagecreatetruecolor)
ZEND_PARSE_PARAMETERS_END();

if (x_size <= 0 || x_size >= INT_MAX) {
zend_argument_value_error(1, "must be greater than 0");
zend_argument_value_error(1, "must be greater than 0 and less than %d", INT_MAX);
RETURN_THROWS();
}

if (y_size <= 0 || y_size >= INT_MAX) {
zend_argument_value_error(2, "must be greater than 0");
zend_argument_value_error(2, "must be greater than 0 and less than %d", INT_MAX);
RETURN_THROWS();
}

Expand Down Expand Up @@ -1355,12 +1355,12 @@ PHP_FUNCTION(imagecreate)
ZEND_PARSE_PARAMETERS_END();

if (x_size <= 0 || x_size >= INT_MAX) {
zend_argument_value_error(1, "must be greater than 0");
zend_argument_value_error(1, "must be greater than 0 and less than %d", INT_MAX);
RETURN_THROWS();
}

if (y_size <= 0 || y_size >= INT_MAX) {
zend_argument_value_error(2, "must be greater than 0");
zend_argument_value_error(2, "must be greater than 0 and less than %d", INT_MAX);
RETURN_THROWS();
}

Expand Down
6 changes: 3 additions & 3 deletions ext/gd/tests/imagecreate_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ trycatch_dump(
);

?>
--EXPECT--
!! [ValueError] imagecreate(): Argument #1 ($width) must be greater than 0
!! [ValueError] imagecreate(): Argument #2 ($height) must be greater than 0
--EXPECTF--
!! [ValueError] imagecreate(): Argument #1 ($width) must be greater than 0 and less than %d
!! [ValueError] imagecreate(): Argument #2 ($height) must be greater than 0 and less than %d
26 changes: 26 additions & 0 deletions ext/gd/tests/imagecreate_error_oversized.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
imagecreate()/imagecreatetruecolor(): oversized dimensions produce a correct error message
--EXTENSIONS--
gd
--FILE--
<?php
foreach ([PHP_INT_MAX, 2147483647, 4294967296] as $v) {
try { imagecreate($v, 1); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
try { imagecreate(1, $v); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
try { imagecreatetruecolor($v, 1); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
try { imagecreatetruecolor(1, $v); } catch (Throwable $e) { echo $e::class, ': ', $e->getMessage(), "\n"; }
}
?>
--EXPECTF--
ValueError: imagecreate(): Argument #1 ($width) must be greater than 0 and less than %d
ValueError: imagecreate(): Argument #2 ($height) must be greater than 0 and less than %d
ValueError: imagecreatetruecolor(): Argument #1 ($width) must be greater than 0 and less than %d
ValueError: imagecreatetruecolor(): Argument #2 ($height) must be greater than 0 and less than %d
ValueError: imagecreate(): Argument #1 ($width) must be greater than 0 and less than %d
ValueError: imagecreate(): Argument #2 ($height) must be greater than 0 and less than %d
ValueError: imagecreatetruecolor(): Argument #1 ($width) must be greater than 0 and less than %d
ValueError: imagecreatetruecolor(): Argument #2 ($height) must be greater than 0 and less than %d
ValueError: imagecreate(): Argument #1 ($width) must be greater than 0 and less than %d
ValueError: imagecreate(): Argument #2 ($height) must be greater than 0 and less than %d
ValueError: imagecreatetruecolor(): Argument #1 ($width) must be greater than 0 and less than %d
ValueError: imagecreatetruecolor(): Argument #2 ($height) must be greater than 0 and less than %d
6 changes: 3 additions & 3 deletions ext/gd/tests/imagecreatetruecolor_error2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ trycatch_dump(
);

?>
--EXPECT--
!! [ValueError] imagecreatetruecolor(): Argument #1 ($width) must be greater than 0
!! [ValueError] imagecreatetruecolor(): Argument #2 ($height) must be greater than 0
--EXPECTF--
!! [ValueError] imagecreatetruecolor(): Argument #1 ($width) must be greater than 0 and less than %d
!! [ValueError] imagecreatetruecolor(): Argument #2 ($height) must be greater than 0 and less than %d
Loading