Bug #68802 [NEW]: PDO::FETCH_SERIALIZE does not unserialize object
| From: | zerkms at zerkms dot ru | Date: | Mon, 12 Jan 2015 01:00:25 +0000 |
| Subject: | Bug #68802 [NEW]: PDO::FETCH_SERIALIZE does not unserialize object | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-189892@lists.php.net to get a copy of this message | ||
From: zerkms at zerkms dot ru
Operating system:
PHP version: Irrelevant
Package: PDO Core
Bug Type: Bug
Bug description:PDO::FETCH_SERIALIZE does not unserialize object
Description:
------------
PDO::FETCH_SERIALIZE flag must enable automatic deserialization of an
object, while it does it in some wrong way.
If you additionally see the
passed data line you will notice that the
argument passed there contains extra data (the class name) that should
not be there.
It causes the whole unserialization process to be broken.
The correspondning test
https://github.com/php/php-src/blob/master/ext/pdo_mysql/tests/pdo_mysql_stmt_fetch_serialize.phpt
is also invalid since it does not check that we can assemble the
original object back.
Test script:
---------------
class foo implements Serializable {
private $data;
public function __construct() {
$this->data = "My private data";
}
public function serialize() {
return serialize($this->data);
}
public function unserialize($data) {
var_dump('passed data: ', $data);
$this->data = unserialize($data);
}
public function getData() {
return $this->data;
}
}
$foo = new foo;
//var_dump(serialize($foo));
$stmt = $pdo->prepare('SELECT \'C:3:"foo":23:{s:15:"My private
data";}\'');
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_SERIALIZE, 'foo');
$data = $stmt->fetch();
var_dump($data);
Expected result:
----------------
object(foo)#5 (1) {
["data":"foo":private]=>
string(15) "My private data"
}
Actual result:
--------------
object(foo)#4 (1) {
["data":"foo":private]=>
object(foo)#5 (1) {
["data":"foo":private]=>
string(15) "My private data"
}
}
--
Edit bug report at https://bugs.php.net/bug.php?id=68802&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68802&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68802&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68802&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68802&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68802&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68802&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68802&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68802&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68802&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68802&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68802&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68802&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68802&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68802&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68802&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68802&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68802&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68802&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68802&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68802&r=mysqlcfg