Skip to content

Commit

Permalink
Merge branch 'PHP-8.3' into PHP-8.4
Browse files Browse the repository at this point in the history
* PHP-8.3:
  Fix GH-16255: Unexpected nan value in ext/gd/libgd/gd_filter.c
  • Loading branch information
nielsdos committed Dec 16, 2024
2 parents 52ebdfb + 6c198e3 commit 7b2b2ec
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ PHP NEWS
. Fixed bug GH-13437 (FPM: ERROR: scoreboard: failed to lock (already
locked)). (Jakub Zelenka)

- GD:
. Fixed bug GH-16255 (Unexpected nan value in ext/gd/libgd/gd_filter.c).
(nielsdos, cmb)

- Iconv:
. Fixed bug GH-17047 (UAF on iconv filter failure). (nielsdos)

Expand Down
19 changes: 18 additions & 1 deletion ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3764,7 +3764,24 @@ PHP_FUNCTION(imageconvolution)
}
}
}
res = gdImageConvolution(im_src, matrix, (float)div, (float)offset);

if (UNEXPECTED(!zend_finite(div))) {
zend_argument_value_error(3, "must be finite");
RETURN_THROWS();
}

float div_float = (float) div;
if (UNEXPECTED(div_float == 0.0f)) {
zend_argument_value_error(3, "must not be 0");
RETURN_THROWS();
}

if (UNEXPECTED(!zend_finite(offset))) {
zend_argument_value_error(4, "must be finite");
RETURN_THROWS();
}

res = gdImageConvolution(im_src, matrix, div_float, (float) offset);

if (res) {
RETURN_TRUE;
Expand Down
34 changes: 34 additions & 0 deletions ext/gd/tests/gh16255.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
GH-16255 (Unexpected nan value in ext/gd/libgd/gd_filter.c)
--EXTENSIONS--
gd
--CREDITS--
cmb69
--FILE--
<?php
$matrix = array(array(1, 0, 1), array(0, 5, 0), array(1, 0, 1));
$im = imagecreatetruecolor(40, 40);

try {
imageconvolution($im, $matrix, NAN, 1.0);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

try {
imageconvolution($im, $matrix, 2.225E-307, 1.0);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

try {
imageconvolution($im, $matrix, 1, NAN);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
imageconvolution(): Argument #3 ($divisor) must be finite
imageconvolution(): Argument #3 ($divisor) must not be 0
imageconvolution(): Argument #4 ($offset) must be finite

0 comments on commit 7b2b2ec

Please sign in to comment.