Skip to content

Commit 76ade71

Browse files
committed
Merge branch 'PHP-8.4'
2 parents ac2b656 + aa815f3 commit 76ade71

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

ext/date/php_date.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5080,9 +5080,11 @@ static bool date_period_init_iso8601_string(php_period_obj *dpobj, zend_class_en
50805080

50815081
static bool date_period_init_finish(php_period_obj *dpobj, zend_long options, zend_long recurrences)
50825082
{
5083-
if (dpobj->end == NULL && recurrences < 1) {
5083+
const zend_long max_recurrences = (INT_MAX - 8);
5084+
5085+
if (dpobj->end == NULL && (recurrences < 1 || recurrences > max_recurrences)) {
50845086
zend_string *func = get_active_function_or_method_name();
5085-
zend_throw_exception_ex(date_ce_date_malformed_period_string_exception, 0, "%s(): Recurrence count must be greater than 0", ZSTR_VAL(func));
5087+
zend_throw_exception_ex(date_ce_date_malformed_period_string_exception, 0, "%s(): Recurrence count must be greater or equal to 1 and lower than " ZEND_LONG_FMT, ZSTR_VAL(func), max_recurrences + 1);
50865088
zend_string_release(func);
50875089
return false;
50885090
}
@@ -5091,8 +5093,17 @@ static bool date_period_init_finish(php_period_obj *dpobj, zend_long options, ze
50915093
dpobj->include_start_date = !(options & PHP_DATE_PERIOD_EXCLUDE_START_DATE);
50925094
dpobj->include_end_date = options & PHP_DATE_PERIOD_INCLUDE_END_DATE;
50935095

5094-
/* recurrrences */
5095-
dpobj->recurrences = recurrences + dpobj->include_start_date + dpobj->include_end_date;
5096+
/* recurrences */
5097+
recurrences += dpobj->include_start_date + dpobj->include_end_date;
5098+
5099+
if (UNEXPECTED(recurrences > max_recurrences)) {
5100+
zend_string *func = get_active_function_or_method_name();
5101+
zend_throw_exception_ex(date_ce_date_malformed_string_exception, 0, "%s(): Recurrence count must be greater or equal to 1 and lower than " ZEND_LONG_FMT " (including options)", ZSTR_VAL(func), max_recurrences + 1);
5102+
zend_string_release(func);
5103+
return false;
5104+
}
5105+
5106+
dpobj->recurrences = (int)recurrences;
50965107

50975108
dpobj->initialized = 1;
50985109

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 greater or equal to 1 and lower than %d
20+
DatePeriod::__construct(): Recurrence count must be greater or equal to 1 and lower than %d

ext/date/tests/date_period_bad_iso_format.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ DateMalformedPeriodStringException: DatePeriod::__construct(): ISO interval must
5050
DateMalformedPeriodStringException: DatePeriod::createFromISO8601String(): ISO interval must contain an interval, "R4/2012-07-01T00:00:00Z" given
5151

5252
Deprecated: Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, use DatePeriod::createFromISO8601String() instead in %s on line %d
53-
DateMalformedPeriodStringException: DatePeriod::__construct(): Recurrence count must be greater than 0
54-
DateMalformedPeriodStringException: DatePeriod::createFromISO8601String(): Recurrence count must be greater than 0
53+
DateMalformedPeriodStringException: DatePeriod::__construct(): Recurrence count must be greater or equal to 1 and lower than %d
54+
DateMalformedPeriodStringException: DatePeriod::createFromISO8601String(): Recurrence count must be greater or equal to 1 and lower than %d

ext/date/tests/gh14709.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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, 2147483640);
10+
} catch (Exception $e) {
11+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
12+
}
13+
14+
try {
15+
new DatePeriod($start, $interval, 2147483639, DatePeriod::EXCLUDE_START_DATE | DatePeriod::INCLUDE_END_DATE);
16+
} catch (Exception $e) {
17+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
18+
}
19+
?>
20+
--EXPECTF--
21+
DateMalformedPeriodStringException: DatePeriod::__construct(): Recurrence count must be greater or equal to 1 and lower than %d
22+
DateMalformedStringException: DatePeriod::__construct(): Recurrence count must be greater or equal to 1 and lower than %d (including options)

0 commit comments

Comments
 (0)