From: Operating system: AIX64 PHP version: 5.3.2 Package: Strings related Bug Type: Bug Bug description:unpack('I', $x) on 64 bit big endian unreliable
Description: ------------ Testing unpack 'I' format on a 64bit big-endian architecture. The result depends on the sign bit in the *next* integer in the packed buffer or a out of buffer byte if it is not that long. A patch which resolves this is below. I think the code ends up producing identical results for the I and i format which may be the most desirable thing but the code looks like it was intended to behave differently. Maybe it can be simplified. Similar to bug #40894 but a different format (I). patch: *** pack.c Thu Mar 11 15:05:11 2010 --- pack.c.orig Thu Mar 11 15:03:20 2010 *************** *** 752,758 **** if (type == 'i') { issigned = input[inputpos + (machine_little_endian ? (sizeof(int) - 1) : 0)] & 0x80; ! } else if (sizeof(long) > 4 && input[inputpos + (machine_little_endian ? (sizeof(int) - 1) : 0)] & 0x80 == 0x80) { v = ~INT_MAX; } --- 752,758 ---- if (type == 'i') { issigned = input[inputpos + (machine_little_endian ? (sizeof(int) - 1) : 0)] & 0x80; ! } else if (sizeof(long) > 4 && (input[inputpos + machine_endian_long_map[3]] & 0x80) == 0x80) { v = ~INT_MAX; } Test script: --------------- <?php echo PHP_INT_MAX."\n"; print_r(unpack('I', pack('I', -10000) . pack('I', 10000))); print_r(unpack('I', pack('I', -10000) . pack('I', -10000))); ?> Expected result: ---------------- 9223372036854775807 Array ( [1] => -10000 ) Array ( [1] => -10000 ) Actual result: -------------- 9223372036854775807 Array ( [1] => 4294957296 ) Array ( [1] => -10000 ) -- Edit bug report at http://bugs.php.net/bug.php?id=51275&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51275&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51275&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51275&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51275&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51275&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51275&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51275&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51275&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51275&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51275&r=support Expected behavior: http://bugs.php.net/fix.php?id=51275&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51275&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51275&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51275&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51275&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51275&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51275&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51275&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51275&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51275&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51275&r=mysqlcfg