Skip to content

Commit 67effbd

Browse files
committed
Fix GH-20936: DatePeriod::__set_state() cannot handle null start
The "current" and "end" field also rely on start_ce, which is set by "start". Therefore, if "current" or "end" are provided, so must "start" be provided.
1 parent 098b1f8 commit 67effbd

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

ext/date/php_date.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5811,7 +5811,7 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has
58115811
php_date_obj *date_obj;
58125812
date_obj = Z_PHPDATE_P(ht_entry);
58135813

5814-
if (!date_obj->time) {
5814+
if (!date_obj->time || !period_obj->start_ce) {
58155815
return 0;
58165816
}
58175817

@@ -5832,7 +5832,7 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has
58325832
php_date_obj *date_obj;
58335833
date_obj = Z_PHPDATE_P(ht_entry);
58345834

5835-
if (!date_obj->time) {
5835+
if (!date_obj->time || !period_obj->start_ce) {
58365836
return 0;
58375837
}
58385838

ext/date/tests/gh20936.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-20936 (DatePeriod::__set_state() cannot handle null start)
3+
--FILE--
4+
<?php
5+
$end = new DateTime('2022-07-16', new DateTimeZone('UTC'));
6+
$interval = new DateInterval('P2D');
7+
try {
8+
DatePeriod::__set_state(['start' => null, 'end' => $end, 'current' => null, 'interval' => $interval, 'recurrences' => 2, 'include_start_date' => false, 'include_end_date' => true]);
9+
} catch (Throwable $e) {
10+
echo $e::class, ": ", $e->getMessage(), "\n";
11+
}
12+
?>
13+
--EXPECT--
14+
Error: Invalid serialization data for DatePeriod object

0 commit comments

Comments
 (0)