Bug #65724 [Nab]: unserialize doesn't always restore referenced objects

2013-10-05 Thread niko dot sams at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=65724&edit=1

 ID: 65724
 User updated by:niko dot sams at gmail dot com
 Reported by:niko dot sams at gmail dot com
 Summary:unserialize doesn't always restore referenced
 objects
 Status: Not a bug
 Type:   Bug
 Package:*General Issues
 Operating System:   Linux
 PHP Version:5.5.4
 Block user comment: N
 Private report: N

 New Comment:

Ok, if this is not a bug which workaround do you suggest?

In my use case the unserialize method tiggers access to a config object which 
is cached and lazily loaded. So it can happen that loading the config is 
triggered inside unserialize.


Previous Comments:

[2013-10-04 14:09:50] m...@php.net

We have a recursive context for Serializable, thus if you unserialize unrelated 
strings in the unserialize callback, you literally throw bricks into the stream.


[2013-09-20 15:16:01] bixuehujin at gmail dot com

Had a test on commit 
@8f146c2(https://github.com/php/php-src/commit/8f146c2bb0dcba3307f08a839554be056e660f34),
 segfault occurred.


[2013-09-20 12:34:47] niko dot sams at gmail dot com

Description:

when doing another unserialize that creates objects in an 
Serializable::unserialize implementation things break, the 'parent' isn't 
unserialized correctly.

ok: PHP 5.3.3-7+squeeze14
ok: PHP 5.3.10-1ubuntu3.6
fail: PHP 5.4.4-14+deb7u2
fail: PHP 5.5.3

See phpt test script:
http://paste.kde.org/p83ce39d0/

Test script:
---
class Bar {}
class Foo implements Serializable {
public $test;
public function __construct($test) { $this->test = $test; }
public function serialize()
{
return $this->test;
}
public function unserialize($serialized)
{
//the following line causes problems
unserialize('O:3:"Bar":1:{s:4:"bar1";O:3:"Bar":0:{}}');
$this->test = $serialized;
}
}
$foo1 = new Foo('foo1');
$foo2 = new Foo('foo2');
$foo3 = new Foo('foo3');
$ar = array(
array(
'instance' => $foo1,
),
array(
'instance' => $foo2,
),
array(
'instance' => $foo3,
'parent' => $foo2
)
);
$ar = serialize($ar);
$ar = unserialize($ar);
print_r($ar);

Expected result:

[parent] => Foo Object ( [test] => foo2 ) )

Actual result:
--
[parent] => foo2






-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65724&edit=1


[PHP-BUG] Bug #65724 [NEW]: unserialize doesn't always restore referenced objects

2013-09-20 Thread niko dot sams at gmail dot com
From: niko dot sams at gmail dot com
Operating system: Linux
PHP version:  5.5.4
Package:  *General Issues
Bug Type: Bug
Bug description:unserialize doesn't always restore referenced objects

Description:

when doing another unserialize that creates objects in an 
Serializable::unserialize implementation things break, the 'parent' isn't 
unserialized correctly.

ok: PHP 5.3.3-7+squeeze14
ok: PHP 5.3.10-1ubuntu3.6
fail: PHP 5.4.4-14+deb7u2
fail: PHP 5.5.3

See phpt test script:
http://paste.kde.org/p83ce39d0/

Test script:
---
class Bar {}
class Foo implements Serializable {
public $test;
public function __construct($test) { $this->test = $test; }
public function serialize()
{
return $this->test;
}
public function unserialize($serialized)
{
//the following line causes problems
unserialize('O:3:"Bar":1:{s:4:"bar1";O:3:"Bar":0:{}}');
$this->test = $serialized;
}
}
$foo1 = new Foo('foo1');
$foo2 = new Foo('foo2');
$foo3 = new Foo('foo3');
$ar = array(
array(
'instance' => $foo1,
),
array(
'instance' => $foo2,
),
array(
'instance' => $foo3,
'parent' => $foo2
)
);
$ar = serialize($ar);
$ar = unserialize($ar);
print_r($ar);

Expected result:

[parent] => Foo Object ( [test] => foo2 ) )

Actual result:
--
[parent] => foo2

-- 
Edit bug report at https://bugs.php.net/bug.php?id=65724&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=65724&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=65724&r=trysnapshot53
Try a snapshot (trunk): 
https://bugs.php.net/fix.php?id=65724&r=trysnapshottrunk
Fixed in SVN:   https://bugs.php.net/fix.php?id=65724&r=fixed
Fixed in release:   https://bugs.php.net/fix.php?id=65724&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65724&r=needtrace
Need Reproduce Script:  https://bugs.php.net/fix.php?id=65724&r=needscript
Try newer version:  https://bugs.php.net/fix.php?id=65724&r=oldversion
Not developer issue:https://bugs.php.net/fix.php?id=65724&r=support
Expected behavior:  https://bugs.php.net/fix.php?id=65724&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=65724&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=65724&r=submittedtwice
register_globals:   https://bugs.php.net/fix.php?id=65724&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65724&r=php4
Daylight Savings:   https://bugs.php.net/fix.php?id=65724&r=dst
IIS Stability:  https://bugs.php.net/fix.php?id=65724&r=isapi
Install GNU Sed:https://bugs.php.net/fix.php?id=65724&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65724&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65724&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=65724&r=mysqlcfg