8000 Test and protect against negative-float-overflow · reactphp/event-loop@730109f · GitHub
[go: up one dir, main page]

Skip to content

Commit 730109f

Browse files
Test and protect against negative-float-overflow
1 parent ddd2b23 commit 730109f

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

src/ExtUvLoop.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,9 @@ private function convertFloatSecondsToMilliseconds($interval)
328328
$maxValue = (int) (\PHP_INT_MAX / 1000);
329329
$intInterval = (int) $interval;
330330

331-
if ($intInterval >= $maxValue) {
331+
if (($intInterval <= 0 && $interval > 1) || $intInterval >= $maxValue) {
332332
throw new \InvalidArgumentException(
333-
"Interval overflow, maximum value is '{$maxValue}', but '{$interval}' passed."
333+
"Interval overflow, value must be lower than '{$maxValue}', but '{$interval}' passed."
334334
);
335335
}
336336

tests/ExtUvLoopTest.php

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,62 @@ public function intervalProvider()
3434
{
3535
$oversizeInterval = PHP_INT_MAX / 1000;
3636
$maxValue = (int) (PHP_INT_MAX / 1000);
37+
$oneMaxValue = $maxValue + 1;
38+
$tenMaxValue = $maxValue + 10;
39+
$tenMillionsMaxValue = $maxValue + 10000000;
40+
$intMax = PHP_INT_MAX;
41+
$oneIntMax = PHP_INT_MAX + 1;
42+
$tenIntMax = PHP_INT_MAX + 10;
43+
$oneHundredIntMax = PHP_INT_MAX + 100;
44+
$oneThousandIntMax = PHP_INT_MAX + 1000;
45+
$tenMillionsIntMax = PHP_INT_MAX + 10000000;
46+
$tenThousandsTimesIntMax = PHP_INT_MAX * 1000;
3747

3848
return array(
3949
array(
4050
$oversizeInterval,
41-
"Interval overflow, maximum value is '{$maxValue}', but '{$oversizeInterval}' passed."
42-
)
51+
"Interval overflow, value must be lower than '{$maxValue}', but '{$oversizeInterval}' passed."
52+
),
53+
array(
54+
$oneMaxValue,
55+
"Interval overflow, value must be lower than '{$maxValue}', but '{$oneMaxValue}' passed.",
56+
),
57+
array(
58+
$tenMaxValue,
59+
"Interval overflow, value must be lower than '{$maxValue}', but '{$tenMaxValue}' passed.",
60+
),
61+
array(
62+
$tenMillionsMaxValue,
63+
"Interval overflow, value must be lower than '{$maxValue}', but '{$tenMillionsMaxValue}' passed.",
64+
),
65+
array(
66+
$intMax,
67+
"Interval overflow, value must be lower than '{$maxValue}', but '{$intMax}' passed.",
68+
),
69+
array(
70+
$oneIntMax,
71+
"Interval overflow, value must be lower than '{$maxValue}', but '{$oneIntMax}' passed.",
72+
),
73+
array(
74+
$tenIntMax,
75+
"Interval overflow, value must be lower than '{$maxValue}', but '{$tenIntMax}' passed.",
76+
),
77+
array(
78+
$oneHundredIntMax,
79+
"Interval overflow, value must be lower than '{$maxValue}', but '{$oneHundredIntMax}' passed.",
80+
),
81+
array(
82+
$oneThousandIntMax,
83+
"Interval overflow, value must be lower than '{$maxValue}', but '{$oneThousandIntMax}' passed.",
84+
),
85+
array(
86+
$tenMillionsIntMax,
87+
5F6F "Interval overflow, value must be lower than '{$maxValue}', but '{$tenMillionsIntMax}' passed.",
88+
),
89+
array(
90+
$tenThousandsTimesIntMax,
91+
"Interval overflow, value must be lower than '{$maxValue}', but '{$tenThousandsTimesIntMax}' passed.",
92+
),
4393
);
4494
}
4595
}

0 commit comments

Comments
 (0)
0