Skip to content
10 changes: 9 additions & 1 deletion Zend/Zend.m4
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ dnl expectations.
dnl
AC_DEFUN([ZEND_CHECK_PRESERVE_NONE], [dnl
AC_CACHE_CHECK([for preserve_none calling convention],
[php_cv_preverve_none],
[php_cv_preserve_none],
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdio.h>
#include <stdint.h>
Expand Down Expand Up @@ -504,7 +504,11 @@ uintptr_t __attribute__((preserve_none)) test(void) {
"movq %2, %%r13\n"
"xorq %3, %%r13\n"
"xorq %%rax, %%rax\n"
#if defined(__APPLE__)
"call _fun\n"
#else
"call fun\n"
#endif
: "=a" (ret)
: "r" (const1), "r" (const2), "r" (key)
: "r12", "r13"
Expand All @@ -515,7 +519,11 @@ uintptr_t __attribute__((preserve_none)) test(void) {
"eor x20, %1, %3\n"
"eor x21, %2, %3\n"
"eor x0, x0, x0\n"
#if defined(__APPLE__)
"bl _fun\n"
#else
"bl fun\n"
#endif
"mov %0, x0\n"
: "=r" (ret)
: "r" (const1), "r" (const2), "r" (key)
Expand Down
10 changes: 10 additions & 0 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2453,11 +2453,21 @@ PHP_FUNCTION(imagegammacorrect)
RETURN_THROWS();
}

if (!zend_finite(input)) {
zend_argument_value_error(2, "must be finite");
RETURN_THROWS();
}

if (output <= 0.0) {
zend_argument_value_error(3, "must be greater than 0");
RETURN_THROWS();
}

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

gamma = input / output;

im = php_gd_libgdimageptr_from_zval_p(IM);
Expand Down
36 changes: 36 additions & 0 deletions ext/gd/tests/gh20551.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
GH-20551: (imagegammacorrect out of range input/output value)
--EXTENSIONS--
gd
--FILE--
<?php
$im = imagecreate(64, 32);

$gammas = [
[NAN, 1.0],
[-NAN, 1.0],
[INF, 1.0],
[-INF, 1.0],
[1.0, NAN],
[1.0, -NAN],
[1.0, INF],
[1.0, -INF],
];

foreach ($gammas as $gamma) {
try {
imagegammacorrect($im, $gamma[0], $gamma[1]);
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
}
?>
--EXPECT--
imagegammacorrect(): Argument #2 ($input_gamma) must be finite
imagegammacorrect(): Argument #2 ($input_gamma) must be finite
imagegammacorrect(): Argument #2 ($input_gamma) must be finite
imagegammacorrect(): Argument #2 ($input_gamma) must be greater than 0
imagegammacorrect(): Argument #3 ($output_gamma) must be finite
imagegammacorrect(): Argument #3 ($output_gamma) must be finite
imagegammacorrect(): Argument #3 ($output_gamma) must be finite
imagegammacorrect(): Argument #3 ($output_gamma) must be greater than 0
2 changes: 1 addition & 1 deletion sapi/cli/php_cli_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ static int status_comp(const void *a, const void *b) /* {{{ */

static const char *get_status_string(int code) /* {{{ */
{
http_response_status_code_pair needle = {code, NULL},
const http_response_status_code_pair needle = {code, NULL},
*result = NULL;

result = bsearch(&needle, http_status_map, http_status_map_len, sizeof(needle), status_comp);
Expand Down