Skip to content

Commit 7445b0f

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. Closes GH-20939.
1 parent b8fc6bd commit 7445b0f

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ PHP NEWS
1313
. Fixed bug GH-21023 (CURLOPT_XFERINFOFUNCTION crash with a null callback).
1414
(David Carlier)
1515

16+
- Date:
17+
. Fixed bug GH-20936 (DatePeriod::__set_state() cannot handle null start).
18+
(ndossche)
19+
1620
- DOM:
1721
. Fixed bug GH-21077 (Accessing Dom\Node::baseURI can throw TypeError).
1822
(ndossche)

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)