From:             jr-php2 at quo dot to
Operating system: Linux x86-64
PHP version:      5.2.4
PHP Bug Type:     Unknown/Other Function
Bug description:  unpack('V') sign-extends result on x86-64

Description:
------------
On x86-64, unpack('V') sign-extends from 32-bit to 64-bit. In other words,
it can return a negative number.
Since 'V' specifies an *unsigned* 32-bit value, this is incorrect; the
upper 32 bits of the 64-bit result should always be zero.

This behavior makes unpack() inconsistent with other functions like
ip2long() and crc32() which never return negative numbers on 64-bit PHP.

Reproduce code:
---------------
$u = unpack('Vresult', chr(200).chr(200).chr(200).chr(200));
echo "unpack = ", $u['result'], "\n";
echo "ip2long = ", ip2long('200.200.200.200'), "\n";

Expected result:
----------------
unpack = -926365496
ip2long = 3368601800

Actual result:
--------------
unpack = 3368601800
ip2long = 3368601800

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

Reply via email to