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.
This commit is contained in:
Christoph M. Becker 2020-03-05 14:57:27 +01:00
parent 9dda3b9eb2
commit b84277297a
3 changed files with 28 additions and 0 deletions

3
NEWS
View file

@ -2,6 +2,9 @@ PHP NEWS
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 7.3.17 ?? ??? ????, PHP 7.3.17
- Spl:
. Fixed bug #75673 (SplStack::unserialize() behavior). (cmb)
19 Mar 2020, PHP 7.3.16 19 Mar 2020, PHP 7.3.16
- Core: - Core:

View file

@ -1185,6 +1185,12 @@ SPL_METHOD(SplDoublyLinkedList, unserialize)
return; return;
} }
while (intern->llist->count > 0) {
zval tmp;
spl_ptr_llist_pop(intern->llist, &tmp);
zval_ptr_dtor(&tmp);
}
s = p = (const unsigned char*)buf; s = p = (const unsigned char*)buf;
PHP_VAR_UNSERIALIZE_INIT(var_hash); PHP_VAR_UNSERIALIZE_INIT(var_hash);

View file

@ -0,0 +1,19 @@
--TEST--
Bug #75673 (SplStack::unserialize() behavior)
--FILE--
<?php
$stack = new SplStack();
$stack->push("one");
$stack->push("two");
$serialized = $stack->serialize();
var_dump($stack->count());
$stack->unserialize($serialized);
var_dump($stack->count());
$stack->unserialize($serialized);
var_dump($stack->count());
?>
--EXPECT--
int(2)
int(2)
int(2)