Skip to content

Commit a5503cf

Browse files
Fix GH-17935: ArrayObject unserialize assertion failure on later modification
1 parent 7c1830b commit a5503cf

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ PHP NEWS
109109
- SPL:
110110
. Fixed bug GH-20614 (SplFixedArray incorrectly handles references
111111
in deserialization). (ndossche)
112+
. Fixed bug GH-17935 (ArrayObject unserialize assertion failure on later
113+
modification). (alexandre-daubois)
112114

113115
- Standard:
114116
. Fix memory leak in array_diff() with custom type checks. (ndossche)

ext/spl/spl_array.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,8 @@ PHP_METHOD(ArrayObject, __serialize)
17791779
/* storage */
17801780
if (intern->ar_flags & SPL_ARRAY_IS_SELF) {
17811781
ZVAL_NULL(&tmp);
1782+
} else if (Z_TYPE(intern->array) == IS_ARRAY) {
1783+
ZVAL_ARR(&tmp, zend_array_dup(Z_ARR(intern->array)));
17821784
} else {
17831785
ZVAL_COPY(&tmp, &intern->array);
17841786
}

ext/spl/tests/bug45826.phpt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,16 @@ array(4) {
9494
[2]=>
9595
object(ArrayObject2)#5 (1) {
9696
["storage":"ArrayObject":private]=>
97-
*RECURSION*
97+
array(3) {
98+
[0]=>
99+
object(stdClass)#8 (0) {
100+
}
101+
[1]=>
102+
object(stdClass)#8 (0) {
103+
}
104+
[2]=>
105+
*RECURSION*
106+
}
98107
}
99108
}
100109
[2]=>

ext/spl/tests/gh17935.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
GH-17935 (ArrayObject __serialize() should not cause assertion failure on modification)
3+
--FILE--
4+
<?php
5+
$o = new ArrayObject();
6+
$s2 = $o->__serialize();
7+
$o['a'] = 'b';
8+
echo "Success\n";
9+
?>
10+
--EXPECT--
11+
Success

0 commit comments

Comments
 (0)