Skip to content

Commit 29433f9

Browse files
committed
Make unserialize() ref unwrapping compatible with 7.0
Also fix output difference in merged test (unrelated).
1 parent 590ef15 commit 29433f9

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

ext/standard/tests/serialize/bug69425.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var_dump($data);
2626
int(1)
2727
array(2) {
2828
[0]=>
29-
object(DateInterval)#1 (15) {
29+
object(DateInterval)#1 (16) {
3030
["y"]=>
3131
int(-1)
3232
["m"]=>
@@ -39,6 +39,8 @@ array(2) {
3939
int(-1)
4040
["s"]=>
4141
int(-1)
42+
["f"]=>
43+
float(-1)
4244
["weekday"]=>
4345
int(-1)
4446
["weekday_behavior"]=>

ext/standard/var.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,6 @@ PHP_FUNCTION(unserialize)
11181118
}
11191119
RETVAL_FALSE;
11201120
} else {
1121-
ZVAL_DEREF(retval);
11221121
ZVAL_COPY(return_value, retval);
11231122
}
11241123

@@ -1130,6 +1129,13 @@ PHP_FUNCTION(unserialize)
11301129
/* Reset to previous allowed_classes in case this is a nested call */
11311130
php_var_unserialize_set_allowed_classes(var_hash, prev_class_hash);
11321131
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
1132+
1133+
/* Per calling convention we must not return a reference here, so unwrap. We're doing this at
1134+
* the very end, because __wakeup() calls performed during UNSERIALIZE_DESTROY might affect
1135+
* the value we unwrap here. This is compatible with behavior in PHP <=7.0. */
1136+
if (Z_ISREF_P(return_value)) {
1137+
zend_unwrap_reference(return_value);
1138+
}
11331139
}
11341140
/* }}} */
11351141

0 commit comments

Comments
 (0)