Skip to content

Commit 33787d5

Browse files
committed
Fix GH-17703: imagescale both width and heigh set with negative values.
Throwing a ValueError in this particular case.
1 parent e9d4fc1 commit 33787d5

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

ext/gd/gd.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3981,6 +3981,11 @@ PHP_FUNCTION(imagescale)
39813981

39823982
im = php_gd_libgdimageptr_from_zval_p(IM);
39833983

3984+
if (tmp_h < 0 && tmp_w < 0) {
3985+
zend_value_error("Argument #2 ($width) and argument #3 ($height) cannot be both negative");
3986+
RETURN_THROWS();
3987+
}
3988+
39843989
if (tmp_h < 0 || tmp_w < 0) {
39853990
/* preserve ratio */
39863991
long src_x, src_y;

ext/gd/tests/gh17703.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-17703 both width and height value being negative triggers ValueError on width.
3+
--EXTENSIONS--
4+
gd
5+
--FILE--
6+
<?php
7+
8+
$img = imagecreatetruecolor ( 256, 1);
9+
10+
try {
11+
imagescale($img, -1, -1, 0);
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage();
14+
}
15+
?>
16+
--EXPECT--
17+
Argument #2 ($width) and argument #3 ($height) cannot be both negative

0 commit comments

Comments
 (0)