#34879 [NEW]: str_replace, array_map corrupt negative array indexes on AMD64 (Opteron/x86_64)

From: Date: Sat, 15 Oct 2005 07:50:55 +0000
Subject: #34879 [NEW]: str_replace, array_map corrupt negative array indexes on AMD64 (Opteron/x86_64)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-86615@lists.php.net to get a copy of this message
From:             brion at pobox dot com
Operating system: Linux
PHP version:      4.4.1RC1
PHP Bug Type:     Arrays related
Bug description:  str_replace, array_map corrupt negative array indexes on AMD64 (Opteron/x86_64)

Description:
------------
On 64-bit Opteron systems, certain functions which operate on
arrays will corrupt negative integer array indexes, turning
them into large positive integers.

I've found at least str_replace, preg_replace, and array_map
to exhibit this behavior.

This bug has been inserting odd, but harmless entries into 
user preferences on Wikipedia, though there might be more 
serious problems caused by it that we haven't yet discovered.

Problem confirmed on PHP 4.4.0, 4.4.1RC1, and 5.1.0RC1
running on Fedora Core 3 for x86_64; compiled PHP with
gcc (GCC) 3.4.4 20050721 (Red Hat 3.4.4-2)


Reproduce code:
---------------
var_dump( str_replace( 'a', 'b', array( -1 => -1 ) ) );


Expected result:
----------------
Running on our 32-bit Linux systems I receive the expected:
array(1) {
  [-1]=>
  string(2) "-1"
}


Actual result:
--------------
On our 64-bit Linux servers, I get an incorrect index:
array(1) {
  [4294967295]=>
  string(2) "-1"
}


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


Thread (6 messages)

« previous php.bugs (#86615) next »