Skip to content

Commit 2484f1e

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #70153 \DateInterval incorrectly unserialized
2 parents ecc9588 + 197568d commit 2484f1e

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

ext/date/php_date.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3986,6 +3986,20 @@ static int php_date_interval_initialize_from_hash(zval **return_value, php_inter
39863986
} \
39873987
} while (0);
39883988

3989+
#define PHP_DATE_INTERVAL_READ_PROPERTY_DAYS(member) \
3990+
do { \
3991+
zval *z_arg = zend_hash_str_find(myht, "days", sizeof("days") - 1); \
3992+
if (z_arg && Z_TYPE_P(z_arg) == IS_FALSE) { \
3993+
(*intobj)->diff->member = -99999; \
3994+
} else if (z_arg && Z_TYPE_P(z_arg) <= IS_STRING) { \
3995+
zend_string *str = zval_get_string(z_arg); \
3996+
DATE_A64I((*intobj)->diff->member, ZSTR_VAL(str)); \
3997+
zend_string_release(str); \
3998+
} else { \
3999+
(*intobj)->diff->member = -1LL; \
4000+
} \
4001+
} while (0);
4002+
39894003
#define PHP_DATE_INTERVAL_READ_PROPERTY_DOUBLE(element, member, def) \
39904004
do { \
39914005
zval *z_arg = zend_hash_str_find(myht, element, sizeof(element) - 1); \
@@ -4014,7 +4028,7 @@ static int php_date_interval_initialize_from_hash(zval **return_value, php_inter
40144028
PHP_DATE_INTERVAL_READ_PROPERTY("weekday_behavior", weekday_behavior, int, -1)
40154029
PHP_DATE_INTERVAL_READ_PROPERTY("first_last_day_of", first_last_day_of, int, -1)
40164030
PHP_DATE_INTERVAL_READ_PROPERTY("invert", invert, int, 0);
4017-
PHP_DATE_INTERVAL_READ_PROPERTY_I64("days", days);
4031+
PHP_DATE_INTERVAL_READ_PROPERTY_DAYS(days);
40184032
PHP_DATE_INTERVAL_READ_PROPERTY("special_type", special.type, unsigned int, 0);
40194033
PHP_DATE_INTERVAL_READ_PROPERTY_I64("special_amount", special.amount);
40204034
PHP_DATE_INTERVAL_READ_PROPERTY("have_weekday_relative", have_weekday_relative, unsigned int, 0);

ext/date/tests/bug48678.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ DateInterval Object
3939
[weekday_behavior] => 0
4040
[first_last_day_of] => 0
4141
[invert] => 0
42-
[days] => 0
42+
[days] =>
4343
[special_type] => 0
4444
[special_amount] => 0
4545
[have_weekday_relative] => 0

ext/date/tests/bug53437.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ object(DatePeriod)#%d (6) {
136136
["invert"]=>
137137
int(0)
138138
["days"]=>
139-
int(0)
139+
bool(false)
140140
["special_type"]=>
141141
int(0)
142142
["special_amount"]=>

ext/date/tests/bug53437_var2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ object(DateInterval)#2 (16) {
7171
["invert"]=>
7272
int(0)
7373
["days"]=>
74-
int(0)
74+
bool(false)
7575
["special_type"]=>
7676
int(0)
7777
["special_amount"]=>

ext/date/tests/bug70153.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #70153 (\DateInterval incorrectly unserialized)
3+
--FILE--
4+
<?php
5+
$i1 = \DateInterval::createFromDateString('+1 month');
6+
$i2 = unserialize(serialize($i1));
7+
var_dump($i1->days, $i2->days);
8+
var_dump($i2->special_amount, $i2->special_amount);
9+
?>
10+
--EXPECT--
11+
bool(false)
12+
bool(false)
13+
int(0)
14+
int(0)

0 commit comments

Comments
 (0)