Bug #53437 [NEW]: Crash when using unserialized DatePeriod instance

From: Date: Wed, 01 Dec 2010 16:15:06 +0000
Subject: Bug #53437 [NEW]: Crash when using unserialized DatePeriod instance
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-156654@lists.php.net to get a copy of this message
From: Operating system: Windows XP SP3 PHP version: 5.3.3 Package: Date/time related Bug Type: Bug Bug description:Crash when using unserialized DatePeriod instance Description: ------------ DatePeriod class does not have the serialization/unserialization logic implemented. Therefore, when unserialized instance is used, script crashes. This is result of serializing the DatePeriod instance: O:10:"DatePeriod":0:{} unserialize() wents fine as well, but when I call foreach() on unserialized instance, the script crashes. Test script: --------------- $dp = new DatePeriod(new DateTime('2010-01-01 UTC'), new DateInterval('P1D'), 2); echo "Original:\r\n"; foreach($dp as $dt) { echo $dt->format('Y-m-d H:i:s')."\r\n"; } echo "\r\n"; $ser = serialize($dp); // $ser is: O:10:"DatePeriod":0:{} // Create dangerous instance $dpu = unserialize($ser); // $dpu has invalid values… echo "Unserialized:\r\n"; // …which leads to CRASH: foreach($dpu as $dt) { echo $dt->format('Y-m-d H:i:s')."\r\n"; } Expected result: ---------------- Original: 2010-01-01 00:00:00 2010-01-02 00:00:00 2010-01-03 00:00:00 Unserialized: 2010-01-01 00:00:00 2010-01-02 00:00:00 2010-01-03 00:00:00 Actual result: -------------- PHP crashes on the "unserialize" line. -- Edit bug report at http://bugs.php.net/bug.php?id=53437&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53437&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53437&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53437&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53437&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53437&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53437&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53437&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53437&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53437&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53437&r=support Expected behavior: http://bugs.php.net/fix.php?id=53437&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53437&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53437&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53437&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53437&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53437&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53437&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53437&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53437&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53437&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53437&r=mysqlcfg

« previous php.bugs (#156654) next »