#43614 [NEW]: incorrect processing of numerical string keys of array (unserialize)

From: Date: Mon, 17 Dec 2007 08:14:36 +0000
Subject: #43614 [NEW]: incorrect processing of numerical string keys of array (unserialize)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-120685@lists.php.net to get a copy of this message
From: dmitriy dot buldakov at toatech dot com Operating system: Mac OS X PHP version: 5.2.5 PHP Bug Type: Arrays related Bug description: incorrect processing of numerical string keys of array (unserialize) Description: ------------ php converts numerical string in array keys to integer if possible. php4 converts those string while unserialize as well as while array processing of php code php5 converts those string while array processing of php code only, and not converts while the unserialize a string As the result - unserialized array can contains fake elements. For example - there is no way to get access to the element by a key. Reproduce code: --------------- <?php $a = unserialize('a:2:{s:2:"10";i:1;s:2:"01";i:2;}'); print $a['10']."\n"; $a['10'] = 3; $a['01'] = 4; print_r($a); foreach ($a as $k => $v) { print 'KEY: '; var_dump($k); print 'VAL: '; var_dump($v); print "\n"; } ?> Expected result: ---------------- Dmitriy-Buldakov:~ dmitry$ php4 test.php 1 Array ( [10] => 3 [01] => 4 ) KEY: int(10) VAL: int(3) KEY: string(2) "01" VAL: int(4) Dmitriy-Buldakov:~ dmitry$ Actual result: -------------- Dmitriy-Buldakov:~ dmitry$ php5 test.php PHP Notice: Undefined index: 10 in /Users/dmitry/test.php on line 5 Notice: Undefined index: 10 in /Users/dmitry/test.php on line 5 Array ( [10] => 1 [01] => 4 [10] => 3 ) KEY: string(2) "10" VAL: int(1) KEY: string(2) "01" VAL: int(4) KEY: int(10) VAL: int(3) Dmitriy-Buldakov:~ dmitry$ -- Edit bug report at http://bugs.php.net/?id=43614&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43614&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43614&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43614&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43614&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43614&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43614&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43614&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43614&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43614&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43614&r=support Expected behavior: http://bugs.php.net/fix.php?id=43614&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43614&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43614&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43614&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43614&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43614&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43614&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43614&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43614&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43614&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43614&r=mysqlcfg

« previous php.bugs (#120685) next »