php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69210 serialize function return corrupted data when sleep has non-string values
Submitted: 2015-03-10 03:59 UTC Modified: 2015-03-23 03:37 UTC
From: jrbasso at gmail dot com Assigned: stas (profile)
Status: Closed Package: *General Issues
PHP Version: 5.6.6 OS: Any
Private report: No CVE-ID: None
 [2015-03-10 03:59 UTC] 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)

Patches

PR-1057.patch (last revision 2015-03-10 04:04 UTC by jrbasso at gmail dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-23 03:37 UTC] stas@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: stas
 [2015-03-23 03:37 UTC] stas@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 10 03:01:29 2024 UTC