Skip to content

Commit 2f2aa54

Browse files
committed
Fix GH-14709 overflow on reccurences for DatePeriod::__construct
1 parent 42908f9 commit 2f2aa54

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

ext/date/php_date.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4798,9 +4798,9 @@ PHP_METHOD(DatePeriod, __construct)
47984798
}
47994799
}
48004800

4801-
if (dpobj->end == NULL && recurrences < 1) {
4801+
if (dpobj->end == NULL && (recurrences < 1 || ZEND_LONG_INT_OVFL(recurrences))) {
48024802
zend_string *func = get_active_function_or_method_name();
4803-
zend_throw_exception_ex(NULL, 0, "%s(): Recurrence count must be greater than 0", ZSTR_VAL(func));
4803+
zend_throw_exception_ex(NULL, 0, "%s(): Recurrence count must be between 1 and %d", ZSTR_VAL(func), INT_MAX);
48044804
zend_string_release(func);
48054805
RETURN_THROWS();
48064806
}
@@ -4809,7 +4809,7 @@ PHP_METHOD(DatePeriod, __construct)
48094809
dpobj->include_start_date = !(options & PHP_DATE_PERIOD_EXCLUDE_START_DATE);
48104810
dpobj->include_end_date = options & PHP_DATE_PERIOD_INCLUDE_END_DATE;
48114811

4812-
/* recurrrences */
4812+
/* recurrences */
48134813
dpobj->recurrences = recurrences + dpobj->include_start_date + dpobj->include_end_date;
48144814

48154815
dpobj->initialized = 1;

ext/date/tests/gh14709.phpt

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

0 commit comments

Comments
 (0)