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
5 changes: 5 additions & 0 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3981,6 +3981,11 @@ PHP_FUNCTION(imagescale)

im = php_gd_libgdimageptr_from_zval_p(IM);

if (tmp_h < 0 && tmp_w < 0) {
zend_value_error("Argument #2 ($width) and argument #3 ($height) cannot be both negative");
RETURN_THROWS();
}

if (tmp_h < 0 || tmp_w < 0) {
/* preserve ratio */
long src_x, src_y;
Expand Down
17 changes: 17 additions & 0 deletions ext/gd/tests/gh17703.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
GH-17703 both width and height value being negative triggers ValueError on width.
--EXTENSIONS--
gd
--FILE--
<?php

$img = imagecreatetruecolor ( 256, 1);

try {
imagescale($img, -1, -1, 0);
} catch (\ValueError $e) {
echo $e->getMessage();
}
?>
--EXPECT--
Argument #2 ($width) and argument #3 ($height) cannot be both negative