Bug #69210 [NEW]: serialize function return corrupted data when sleep has non-string values
From: jrbasso at gmail dot com
Operating system: Any
PHP version: 5.6.6
Package: *General Issues
Bug Type: Bug
Bug description:serialize function return corrupted data when sleep has non-string values
Description:
------------
When serializing an object that has a sleep method and this method
returns a non-string value the value generated by serialize is corrupted
and can't be unserialized.
It works fine with values that are strings but not attribute (see
http://3v4l.org/Fprda), but it doesn't with non-string
values (see
http://3v4l.org/81nem or the test script below).
HHVM works fine with non-strings. I wrote a patch that makes the PHP to
works the same way (patch attached and available on
https://github.com/php/php-src/pull/1057).
Test script:
---------------
<?php
class C {
public $a = true;
public function __sleep() {
return ['a', 1];
}
}
$a = new C;
$s = serialize($a);
var_dump($s);
var_dump(unserialize($s));
Expected result:
----------------
Notice: serialize(): "1" returned as member variable from __sleep() but
does not exist in /in/81nem on line 13
string(30) "O:1:"C":2:{s:1:"a";b:1;i:1;N;}"
object(C)#2 (2) {
["a"]=>
bool(true)
["1"]=>
NULL
}
Actual result:
--------------
Notice: serialize(): __sleep should return an array only containing the
names of instance-variables to serialize. in /in/81nem on line 13
string(26) "O:1:"C":2:{s:1:"a";b:1;N;}"
Notice: unserialize(): Error at offset 25 of 26 bytes in /in/81nem on
line 15
bool(false)
--
Edit bug report at https://bugs.php.net/bug.php?id=69210&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69210&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69210&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69210&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69210&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69210&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69210&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69210&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69210&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69210&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69210&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69210&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69210&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69210&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69210&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69210&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69210&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69210&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69210&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69210&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69210&r=mysqlcfg
Thread (2 messages)
- jrbasso at gmail dot com