Skip to content

Commit 0b28914

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
2 parents 459d79d + 2375187 commit 0b28914

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ PHP NEWS
4040
. Fixed bug GH-14775 (range function overflow with negative step argument).
4141
(David Carlier)
4242
. Fix 32-bit wordwrap test failures. (orlitzky)
43+
. Fixed bug GH-14774 (time_sleep_until overflow). (David Carlier)
4344

4445
- Treewide:
4546
. Fix compatibility with libxml2 2.13.2. (nielsdos)

ext/standard/basic_functions.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,7 @@ PHP_FUNCTION(time_sleep_until)
12201220
struct timespec php_req, php_rem;
12211221
uint64_t current_ns, target_ns, diff_ns;
12221222
const uint64_t ns_per_sec = 1000000000;
1223+
const double top_target_sec = (double)(UINT64_MAX / ns_per_sec);
12231224

12241225
ZEND_PARSE_PARAMETERS_START(1, 1)
12251226
Z_PARAM_DOUBLE(target_secs)
@@ -1229,6 +1230,11 @@ PHP_FUNCTION(time_sleep_until)
12291230
RETURN_FALSE;
12301231
}
12311232

1233+
if (UNEXPECTED(!(target_secs >= 0 && target_secs <= top_target_sec))) {
1234+
zend_argument_value_error(1, "must be between 0 and %" PRIu64, (uint64_t)top_target_sec);
1235+
RETURN_THROWS();
1236+
}
1237+
12321238
target_ns = (uint64_t) (target_secs * ns_per_sec);
12331239
current_ns = ((uint64_t) tm.tv_sec) * ns_per_sec + ((uint64_t) tm.tv_usec) * 1000;
12341240
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)