-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #74699 - Broken ArrayIterator unserializing
- Loading branch information
1 parent
51cdd3d
commit afc2282
Showing
4 changed files
with
147 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--TEST-- | ||
Bug #74669: Unserialize ArrayIterator broken | ||
--FILE-- | ||
<?php | ||
|
||
class Container implements Iterator | ||
{ | ||
public $container; | ||
public $iterator; | ||
|
||
public function __construct() | ||
{ | ||
$this->container = new ArrayObject(); | ||
$this->iterator = $this->container->getIterator(); | ||
} | ||
|
||
public function append($element) | ||
{ | ||
$this->container->append($element); | ||
} | ||
|
||
public function current() | ||
{ | ||
return $this->iterator->current(); | ||
} | ||
|
||
public function next() | ||
{ | ||
$this->iterator->next(); | ||
} | ||
|
||
public function key() | ||
{ | ||
return $this->iterator->key(); | ||
} | ||
|
||
public function valid() | ||
{ | ||
return $this->iterator->valid(); | ||
} | ||
|
||
public function rewind() | ||
{ | ||
$this->iterator->rewind(); | ||
} | ||
} | ||
|
||
class SelfArray extends ArrayObject | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct($this); | ||
} | ||
} | ||
|
||
$container = new Container(); | ||
$container->append('test1'); | ||
$container->append('test2'); | ||
$container->valid(); | ||
$serialized = serialize($container); | ||
unset($container); | ||
|
||
$container = unserialize($serialized); | ||
|
||
foreach ($container as $key => $value) { | ||
echo $key . ' => ' . $value . PHP_EOL; | ||
} | ||
|
||
$arObj = new ArrayObject(['test1', 'test2']); | ||
$serialized = serialize($container); | ||
unset($arObj); | ||
|
||
$arObj = unserialize($serialized); | ||
foreach($arObj as $key => $value) { | ||
echo $key . ' => ' . $value . PHP_EOL; | ||
} | ||
|
||
$payload = 'x:i:33554432;O:8:"stdClass":0:{};m:a:0:{}'; | ||
$str = 'C:11:"ArrayObject":' . strlen($payload) . ':{' . $payload . '}'; | ||
|
||
$ao = unserialize($str); | ||
var_dump($ao['foo']); | ||
|
||
$selfArray = new SelfArray(); | ||
$selfArray['foo'] = 'bar'; | ||
var_dump($selfArray); | ||
$serialized = serialize($selfArray); | ||
var_dump($serialized); | ||
unset($selfArray); | ||
$selfArray = unserialize($serialized); | ||
var_dump($selfArray); | ||
var_dump($selfArray['foo']); | ||
|
||
?> | ||
--EXPECTF-- | ||
0 => test1 | ||
1 => test2 | ||
0 => test1 | ||
1 => test2 | ||
|
||
Notice: Undefined index: foo in %s on line %s | ||
NULL | ||
object(SelfArray)#9 (1) { | ||
["foo"]=> | ||
string(3) "bar" | ||
} | ||
string(62) "C:9:"SelfArray":41:{x:i:16777216;m:a:1:{s:3:"foo";s:3:"bar";}}" | ||
object(SelfArray)#9 (1) { | ||
["foo"]=> | ||
string(3) "bar" | ||
} | ||
string(3) "bar" |