Skip to content

Commit 5cb9f64

Browse files
committed
changes from feedback
1 parent 0814f2a commit 5cb9f64

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
@@ -4809,8 +4809,17 @@ 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+
recurrences += dpobj->include_start_date + dpobj->include_end_date;
4813+
4814+
if (UNEXPECTED(ZEND_LONG_INT_OVFL(recurrences))) {
4815+
zend_string *func = get_active_function_or_method_name();
4816+
zend_throw_exception_ex(NULL, 0, "%s(): Recurrence count must be between 1 and %d (including options)", ZSTR_VAL(func), INT_MAX);
4817+
zend_string_release(func);
4818+
RETURN_THROWS();
4819+
}
4820+
48124821
/* recurrences */
4813-
dpobj->recurrences = recurrences + dpobj->include_start_date + dpobj->include_end_date;
4822+
dpobj->recurrences = (int)recurrences;
48144823

48154824
dpobj->initialized = 1;
48164825

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)