Skip to content

Commit b15189f

Browse files
jhdxrcmb69
authored andcommitted
Fix #77298: segfault occurs when add property to unserialized empty ArrayObject
1 parent 95193c3 commit b15189f

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 7.3.2
44

5+
- SPL:
6+
. Fixed bug #77298 (segfault occurs when add property to unserialized empty
7+
ArrayObject). (jhdxr)
8+
59
03 Jan 2019, PHP 7.3.1
610

711
- Core:

ext/spl/spl_array.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,9 @@ SPL_METHOD(Array, unserialize)
18421842

18431843
if (Z_TYPE_P(array) == IS_ARRAY) {
18441844
zval_ptr_dtor(&intern->array);
1845-
ZVAL_COPY(&intern->array, array);
1845+
ZVAL_COPY_VALUE(&intern->array, array);
1846+
ZVAL_NULL(array);
1847+
SEPARATE_ARRAY(&intern->array);
18461848
} else {
18471849
spl_array_set_array(object, intern, array, 0L, 1);
18481850
}

ext/spl/tests/bug77298.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Bug #77298 (segfault occurs when add property to unserialized ArrayObject)
3+
--FILE--
4+
<?php
5+
$o = new ArrayObject();
6+
$o2 = unserialize(serialize($o));
7+
$o2[1]=123;
8+
var_dump($o2);
9+
10+
$o3 = new ArrayObject();
11+
$o3->unserialize($o->serialize());
12+
$o3['xm']=456;
13+
var_dump($o3);
14+
--EXPECT--
15+
object(ArrayObject)#2 (1) {
16+
["storage":"ArrayObject":private]=>
17+
array(1) {
18+
[1]=>
19+
int(123)
20+
}
21+
}
22+
object(ArrayObject)#3 (1) {
23+
["storage":"ArrayObject":private]=>
24+
array(1) {
25+
["xm"]=>
26+
int(456)
27+
}
28+
}

0 commit comments

Comments
 (0)