Skip to content

Commit 9bc3418

Browse files
committed
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.
1 parent 41af933 commit 9bc3418

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ PHP NEWS
1818
. Fixed bug GH-16302 (CurlMultiHandle holds a reference to CurlHandle if
1919
curl_multi_add_handle fails). (timwolla)
2020

21+
- Date:
22+
. Fixed bug GH-16454 (Unhandled INF in date_sunset() with tiny $utcOffset).
23+
(cmb)
24+
2125
- DOM:
2226
. Fixed bug GH-16316 (DOMXPath breaks when not initialized properly).
2327
(nielsdos)

ext/date/php_date.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5140,6 +5140,9 @@ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, bool calc_s
51405140
if (N > 24 || N < 0) {
51415141
N -= floor(N / 24) * 24;
51425142
}
5143+
if (N > 24 || N < 0) {
5144+
RETURN_FALSE;
5145+
}
51435146

51445147
switch (retformat) {
51455148
case SUNFUNCS_RET_STRING:

ext/date/tests/gh16454.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-16454 (Unhandled INF in date_sunset() with tiny $utcOffset)
3+
--FILE--
4+
<?php
5+
var_dump(date_sunrise(0, SUNFUNCS_RET_STRING, 61, -150, 90, PHP_FLOAT_MAX));
6+
var_dump(date_sunrise(0, SUNFUNCS_RET_STRING, 61, -150, 90, -PHP_FLOAT_MAX));
7+
var_dump(date_sunset(0, SUNFUNCS_RET_STRING, 61, -150, 90, PHP_FLOAT_MAX));
8+
var_dump(date_sunset(0, SUNFUNCS_RET_STRING, 61, -150, 90, -PHP_FLOAT_MAX));
9+
?>
10+
--EXPECTF--
11+
Deprecated: Function date_sunrise() is deprecated in %s on line %d
12+
bool(false)
13+
14+
Deprecated: Function date_sunrise() is deprecated in %s on line %d
15+
bool(false)
16+
17+
Deprecated: Function date_sunset() is deprecated in %s on line %d
18+
bool(false)
19+
20+
Deprecated: Function date_sunset() is deprecated in %s on line %d
21+
bool(false)

0 commit comments

Comments
 (0)