Skip to content

Commit dfa93a3

Browse files
committed
Fix GH-14709 overflow on recurrences for DatePeriod::__construct
1 parent f9453a8 commit dfa93a3

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

ext/date/php_date.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4808,9 +4808,9 @@ PHP_METHOD(DatePeriod, __construct)
48084808
}
48094809
}
48104810

4811-
if (dpobj->end == NULL && recurrences < 1) {
4811+
if (dpobj->end == NULL && (recurrences < 1 || ZEND_LONG_INT_OVFL(recurrences))) {
48124812
zend_string *func = get_active_function_or_method_name();
4813-
zend_throw_exception_ex(NULL, 0, "%s(): Recurrence count must be greater than 0", ZSTR_VAL(func));
4813+
zend_throw_exception_ex(NULL, 0, "%s(): Recurrence count must be between 1 and %d", ZSTR_VAL(func), INT_MAX);
48144814
zend_string_release(func);
48154815
RETURN_THROWS();
48164816
}
@@ -4819,7 +4819,7 @@ PHP_METHOD(DatePeriod, __construct)
48194819
dpobj->include_start_date = !(options & PHP_DATE_PERIOD_EXCLUDE_START_DATE);
48204820
dpobj->include_end_date = options & PHP_DATE_PERIOD_INCLUDE_END_DATE;
48214821

4822-
/* recurrrences */
4822+
/* recurrences */
48234823
dpobj->recurrences = recurrences + dpobj->include_start_date + dpobj->include_end_date;
48244824

48254825
dpobj->initialized = 1;

ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ try {
1515
}
1616

1717
?>
18-
--EXPECT--
19-
DatePeriod::__construct(): Recurrence count must be greater than 0
20-
DatePeriod::__construct(): Recurrence count must be greater than 0
18+
--EXPECTF--
19+
DatePeriod::__construct(): Recurrence count must be between 1 and %d
20+
DatePeriod::__construct(): Recurrence count must be between 1 and %d

ext/date/tests/gh14709.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug GH-14709 overflow on reccurences parameter
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+
$start = new DateTime('2018-12-31 00:00:00');
10+
$interval = new DateInterval('P1M');
11+
12+
try {
13+
new DatePeriod($start, $interval, PHP_INT_MAX);
14+
} catch (Exception $e) {
15+
echo $e->getMessage();
16+
}
17+
?>
18+
--EXPECTF--
19+
DatePeriod::__construct(): Recurrence count must be between 1 and %d

0 commit comments

Comments
 (0)