Skip to content

Commit dc7b661

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

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ PHP NEWS
1818
. Fixed bug GH-17609 (Typo in error message: Dom\NO_DEFAULT_NS instead of
1919
Dom\HTML_NO_DEFAULT_NS). (nielsdos)
2020

21+
- GD:
22+
. Fixed bug GH-17703 (imagescale with both width and height negative values
23+
triggers only an Exception on width). (David Carlier)
24+
2125
- MBString:
2226
. Fixed bug GH-17503 (Undefined float conversion in mb_convert_variables).
2327
(cmb)

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,9 @@ PHP 8.4 UPGRADE NOTES
627627
. DOMDocument::registerNodeClass() now has a tentative return type of true.
628628
Previously, the return type was bool but only true could be returned in practice.
629629

630+
- GD:
631+
. imagescale now throws a ValueError when both width and height arguments are negative.
632+
630633
- Hash:
631634
. Changed the return type of hash_update() to true. It was already the case that only
632635
true could be returned, but the stub was not updated yet.

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)