Bug #69210 [Opn->Csd]: serialize function return corrupted data when sleep has non-string values

From: Date: Mon, 23 Mar 2015 03:37:12 +0000
Subject: Bug #69210 [Opn->Csd]: serialize function return corrupted data when sleep has non-string values
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191537@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69210&edit=1

 ID:                 69210
 Updated by:         stas@php.net
 Reported by:        jrbasso at gmail dot com
 Summary:            serialize function return corrupted data when sleep
                     has non-string values
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            *General Issues
 Operating System:   Any
 PHP Version:        5.6.6
-Assigned To:        
+Assigned To:        stas
 Block user comment: N
 Private report:     N

 New Comment:

The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------
[2015-03-10 03:59:34] jrbasso at gmail dot com

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 this bug report at https://bugs.php.net/bug.php?id=69210&edit=1


Thread (2 messages)

« previous php.bugs (#191537) next »