Skip to content

Commit b842772

Browse files
committed
Fix #75673: SplStack::unserialize() behavior
Even though `SplStack::unserialize()` is not supposed to be called on an already constructed instance, it is probably better if the method clears the stack before actually unserializing.
1 parent 9dda3b9 commit b842772

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

NEWS

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

5+
- Spl:
6+
. Fixed bug #75673 (SplStack::unserialize() behavior). (cmb)
7+
58
19 Mar 2020, PHP 7.3.16
69

710
- Core:

ext/spl/spl_dllist.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,12 @@ SPL_METHOD(SplDoublyLinkedList, unserialize)
11851185
return;
11861186
}
11871187

1188+
while (intern->llist->count > 0) {
1189+
zval tmp;
1190+
spl_ptr_llist_pop(intern->llist, &tmp);
1191+
zval_ptr_dtor(&tmp);
1192+
}
1193+
11881194
s = p = (const unsigned char*)buf;
11891195
PHP_VAR_UNSERIALIZE_INIT(var_hash);
11901196

ext/spl/tests/bug75673.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #75673 (SplStack::unserialize() behavior)
3+
--FILE--
4+
<?php
5+
$stack = new SplStack();
6+
$stack->push("one");
7+
$stack->push("two");
8+
9+
$serialized = $stack->serialize();
10+
var_dump($stack->count());
11+
$stack->unserialize($serialized);
12+
var_dump($stack->count());
13+
$stack->unserialize($serialized);
14+
var_dump($stack->count());
15+
?>
16+
--EXPECT--
17+
int(2)
18+
int(2)
19+
int(2)

0 commit comments

Comments
 (0)