From:             wiart at yahoo dot com
Operating system: Red Hat Taroon 64bits
PHP version:      4.3.10
PHP Bug Type:     Arrays related
Bug description:  Implicit cast to int of a key in an array produce an integer 
overflow

Description:
------------
I use in my code in an array a key that is a string only composed of
numbers ("20041001103319").
The problem is that this key is automatically converted into an int by PHP
and as it is a long string, it produces an integer overflow for the array
index (see the code and the Actual result) after serialization and then
unserialization.

Note that I compiled PHP 4.3.10 on my laptop (32 bits) and there is no
problem at all (I can see the Expected result), but when I compile on an
AMD 64 (Opteron) machine, the wrong (Actual result) is shown.

(I've also saw this bug with a 4.3.2 on the Opteron machine).

Problem with cast of strings into int when 64 bits ... 


Note that if I try on my laptop with a shorter key (ie "2004100") that
does not overflows the int capacity, it is also automatically casted into
an int.


My conclusion is "Never use as keys in arrays strings only composed of
numbers". But I think that at least a notice should be displayed for such
implicit casts.
Or maybe I missed something in the documentation. In this case, sorry for
the loss if time.

It is most related with Bug #28972 but in this case, we can see the
difference in the treatment between 32 and 64 bits arch.


Reproduce code:
---------------
$arr["20041001103319"] = 'test';
var_dump( $arr);

$arr_in_str = serialize($arr);
print "Now result is: $arr_in_str<BR />";

$final_arr = unserialize($arr_in_str);
print "The final unserialized array:<BR />";
var_dump($final_arr);

Expected result:
----------------
array(1) { ["20041001103319"]=>  string(4) "test" } 
Now result is: a:1:{s:14:"20041001103319";s:4:"test";}
The final unserialized array:
array(1) { ["20041001103319"]=> string(4) "test" }

Actual result:
--------------
array(1) { [20041001103319]=>  string(4) "test" } 
Now result is: a:1:{i:20041001103319;s:4:"test";}
The final unserialized array:
array(1) { [683700183]=> string(4) "test" }

-- 
Edit bug report at http://bugs.php.net/?id=31117&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=31117&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=31117&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=31117&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=31117&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=31117&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=31117&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=31117&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=31117&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=31117&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=31117&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=31117&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=31117&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=31117&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=31117&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=31117&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=31117&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=31117&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=31117&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=31117&r=mysqlcfg

Reply via email to