Skip to content

Commit 6c198e3

Browse files
committed
Fix GH-16255: Unexpected nan value in ext/gd/libgd/gd_filter.c
Closes GH-17169.
1 parent 2df9f32 commit 6c198e3

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ PHP NEWS
1717
. Fixed bug GH-13437 (FPM: ERROR: scoreboard: failed to lock (already
1818
locked)). (Jakub Zelenka)
1919

20+
- GD:
21+
. Fixed bug GH-16255 (Unexpected nan value in ext/gd/libgd/gd_filter.c).
22+
(nielsdos, cmb)
23+
2024
- Iconv:
2125
. Fixed bug GH-17047 (UAF on iconv filter failure). (nielsdos)
2226

ext/gd/gd.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -3433,7 +3433,24 @@ PHP_FUNCTION(imageconvolution)
34333433
}
34343434
}
34353435
}
3436-
res = gdImageConvolution(im_src, matrix, (float)div, (float)offset);
3436+
3437+
if (UNEXPECTED(!zend_finite(div))) {
3438+
zend_argument_value_error(3, "must be finite");
3439+
RETURN_THROWS();
3440+
}
3441+
3442+
float div_float = (float) div;
3443+
if (UNEXPECTED(div_float == 0.0f)) {
3444+
zend_argument_value_error(3, "must not be 0");
3445+
RETURN_THROWS();
3446+
}
3447+
3448+
if (UNEXPECTED(!zend_finite(offset))) {
3449+
zend_argument_value_error(4, "must be finite");
3450+
RETURN_THROWS();
3451+
}
3452+
3453+
res = gdImageConvolution(im_src, matrix, div_float, (float) offset);
34373454

34383455
if (res) {
34393456
RETURN_TRUE;

ext/gd/tests/gh16255.phpt

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
GH-16255 (Unexpected nan value in ext/gd/libgd/gd_filter.c)
3+
--EXTENSIONS--
4+
gd
5+
--CREDITS--
6+
cmb69
7+
--FILE--
8+
<?php
9+
$matrix = array(array(1, 0, 1), array(0, 5, 0), array(1, 0, 1));
10+
$im = imagecreatetruecolor(40, 40);
11+
12+
try {
13+
imageconvolution($im, $matrix, NAN, 1.0);
14+
} catch (ValueError $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
18+
try {
19+
imageconvolution($im, $matrix, 2.225E-307, 1.0);
20+
} catch (ValueError $e) {
21+
echo $e->getMessage(), "\n";
22+
}
23+
24+
try {
25+
imageconvolution($im, $matrix, 1, NAN);
26+
} catch (ValueError $e) {
27+
echo $e->getMessage(), "\n";
28+
}
29+
30+
?>
31+
--EXPECT--
32+
imageconvolution(): Argument #3 ($divisor) must be finite
33+
imageconvolution(): Argument #3 ($divisor) must not be 0
34+
imageconvolution(): Argument #4 ($offset) must be finite

0 commit comments

Comments
 (0)