Skip to content

Commit c14fa48

Browse files
committed
Merge branch 'PHP-8.3'
2 parents b41e90c + 0b28914 commit c14fa48

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

ext/standard/basic_functions.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,7 @@ PHP_FUNCTION(time_sleep_until)
11951195
struct timespec php_req, php_rem;
11961196
uint64_t current_ns, target_ns, diff_ns;
11971197
const uint64_t ns_per_sec = 1000000000;
1198+
const double top_target_sec = (double)(UINT64_MAX / ns_per_sec);
11981199

11991200
ZEND_PARSE_PARAMETERS_START(1, 1)
12001201
Z_PARAM_DOUBLE(target_secs)
@@ -1204,6 +1205,11 @@ PHP_FUNCTION(time_sleep_until)
12041205
RETURN_FALSE;
12051206
}
12061207

1208+
if (UNEXPECTED(!(target_secs >= 0 && target_secs <= top_target_sec))) {
1209+
zend_argument_value_error(1, "must be between 0 and %" PRIu64, (uint64_t)top_target_sec);
1210+
RETURN_THROWS();
1211+
}
1212+
12071213
target_ns = (uint64_t) (target_secs * ns_per_sec);
12081214
current_ns = ((uint64_t) tm.tv_sec) * ns_per_sec + ((uint64_t) tm.tv_usec) * 1000;
12091215
if (target_ns < current_ns) {

ext/standard/tests/misc/gh14774.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-14774 time_sleep_until overflow
3+
--SKIPIF--
4+
<?php
5+
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
6+
?>
7+
--FILE--
8+
<?php
9+
foreach([INF, -INF, 10e300, -10e300, NAN, -NAN] as $var) {
10+
try {
11+
time_sleep_until($var);
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage() . PHP_EOL;
14+
}
15+
}
16+
?>
17+
--EXPECTF--
18+
time_sleep_until(): Argument #1 ($timestamp) must be between 0 and %d
19+
time_sleep_until(): Argument #1 ($timestamp) must be between 0 and %d
20+
time_sleep_until(): Argument #1 ($timestamp) must be between 0 and %d
21+
time_sleep_until(): Argument #1 ($timestamp) must be between 0 and %d
22+
time_sleep_until(): Argument #1 ($timestamp) must be between 0 and %d
23+
time_sleep_until(): Argument #1 ($timestamp) must be between 0 and %d

0 commit comments

Comments
 (0)