From 9bc34182b6fc9905215c6b0e084f3b239ac8efe4 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 17 Oct 2024 18:14:14 +0200 Subject: [PATCH] Fix GH-16454: Unhandled INF in date_sunset() with tiny $utcOffset After normalization, `N` is supposed to be in range [0, 24], but for very large and very small `$utcOffset` this is not necessarily the case, since the normalization might yied `-inf` or `inf`. If that happens, we let the function fail silently, since it is highly unlikely that such `$utcOffset`s are passed in practice. Closes GH-16483. --- NEWS | 4 ++++ ext/date/php_date.c | 3 +++ ext/date/tests/gh16454.phpt | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 ext/date/tests/gh16454.phpt diff --git a/NEWS b/NEWS index 103b778aacf..3904112a6b5 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,10 @@ PHP NEWS . Fixed bug GH-16302 (CurlMultiHandle holds a reference to CurlHandle if curl_multi_add_handle fails). (timwolla) +- Date: + . Fixed bug GH-16454 (Unhandled INF in date_sunset() with tiny $utcOffset). + (cmb) + - DOM: . Fixed bug GH-16316 (DOMXPath breaks when not initialized properly). (nielsdos) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index dc9eb995b8f..1f49a7f0e0b 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -5140,6 +5140,9 @@ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, bool calc_s if (N > 24 || N < 0) { N -= floor(N / 24) * 24; } + if (N > 24 || N < 0) { + RETURN_FALSE; + } switch (retformat) { case SUNFUNCS_RET_STRING: diff --git a/ext/date/tests/gh16454.phpt b/ext/date/tests/gh16454.phpt new file mode 100644 index 00000000000..3d57276ddf5 --- /dev/null +++ b/ext/date/tests/gh16454.phpt @@ -0,0 +1,21 @@ +--TEST-- +GH-16454 (Unhandled INF in date_sunset() with tiny $utcOffset) +--FILE-- + +--EXPECTF-- +Deprecated: Function date_sunrise() is deprecated in %s on line %d +bool(false) + +Deprecated: Function date_sunrise() is deprecated in %s on line %d +bool(false) + +Deprecated: Function date_sunset() is deprecated in %s on line %d +bool(false) + +Deprecated: Function date_sunset() is deprecated in %s on line %d +bool(false)