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: 8 additions & 0 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3689,9 +3689,17 @@ PHP_FUNCTION(imagescale)
src_y = gdImageSY(im);

if (src_x && tmp_h < 0) {
if (tmp_w > (ZEND_LONG_MAX / src_y)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could allow a bit higher (multiple of src_x) value if it was changed to tmp_w * (src_y / src_x) but not sure if it's worth it...

zend_argument_value_error(2, "must be less than or equal to " ZEND_LONG_FMT, (zend_long)(ZEND_LONG_MAX / src_y));
RETURN_THROWS();
}
tmp_h = tmp_w * src_y / src_x;
}
if (src_y && tmp_w < 0) {
if (tmp_h > (ZEND_LONG_MAX / src_x)) {
zend_argument_value_error(3, "must be less than or equal to " ZEND_LONG_FMT, (zend_long)(ZEND_LONG_MAX / src_x));
RETURN_THROWS();
}
tmp_w = tmp_h * src_x / src_y;
}
}
Expand Down
22 changes: 22 additions & 0 deletions ext/gd/tests/gh20602.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
GH-20551: (imagegammacorrect out of range input/output value)
--EXTENSIONS--
gd
--FILE--
<?php
$im = imagecreatetruecolor(16, 16);

try {
imagescale($im, PHP_INT_MAX, -1);
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
try {
imagescale($im, -1, PHP_INT_MAX);
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
imagescale(): Argument #2 ($width) must be less than or equal to %d
imagescale(): Argument #3 ($height) must be less than or equal to %d
Loading