Skip to content

Commit 6957554

Browse files
committed
changes from feedback
1 parent dfa93a3 commit 6957554

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

ext/date/php_date.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4819,8 +4819,17 @@ 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+
recurrences += dpobj->include_start_date + dpobj->include_end_date;
4823+
4824+
if (UNEXPECTED(ZEND_LONG_INT_OVFL(recurrences))) {
4825+
zend_string *func = get_active_function_or_method_name();
4826+
zend_throw_exception_ex(NULL, 0, "%s(): Recurrence count must be between 1 and %d (including options)", ZSTR_VAL(func), INT_MAX);
4827+
zend_string_release(func);
4828+
RETURN_THROWS();
4829+
}
4830+
48224831
/* recurrences */
4823-
dpobj->recurrences = recurrences + dpobj->include_start_date + dpobj->include_end_date;
4832+
dpobj->recurrences = (int)recurrences;
48244833

48254834
dpobj->initialized = 1;
48264835

ext/date/tests/gh14709.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@ $interval = new DateInterval('P1M');
1111

1212
try {
1313
new DatePeriod($start, $interval, PHP_INT_MAX);
14+
} catch (Exception $e) {
15+
echo $e->getMessage() . PHP_EOL;
16+
}
17+
18+
try {
19+
new DatePeriod($start, $interval, 2147483647, DatePeriod::EXCLUDE_START_DATE | DatePeriod::INCLUDE_END_DATE);
1420
} catch (Exception $e) {
1521
echo $e->getMessage();
1622
}
1723
?>
1824
--EXPECTF--
1925
DatePeriod::__construct(): Recurrence count must be between 1 and %d
26+
DatePeriod::__construct(): Recurrence count must be between 1 and %d (including options)

0 commit comments

Comments
 (0)