#40543 [Com]: pack/unpack bug

From: Date: Mon, 23 Apr 2007 17:19:13 +0000
Subject: #40543 [Com]: pack/unpack bug
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-111828@lists.php.net to get a copy of this message
ID: 40543 Comment by: petr dot stastny at centrum dot cz Reported By: dedmajor at gmail dot com Status: Feedback Bug Type: Strings related Operating System: linux x86_64 PHP Version: 5.2.1 New Comment: Okay, I will say exactly where I have this problem: PHP 5.2.1 # cat /proc/cpuinfo processor : 0 vendor_id : AuthenticAMD cpu family : 15 model : 67 model name : AMD Athlon(tm) 64 X2 Dual Core Processor 3800+ # uname -a Linux silver 2.6.18-8.1.1.el5 #1 SMP Mon Apr 9 09:43:24 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux php -r 'print_r(unpack("N", pack("N", 41445))); returns the same as metioned int the original message about this bug: -2147442203 If you use sprintf('%b',....), you can see: 1111111111111111111111111111111110000000000000001010000111100101 First 32 bits are set to 1. There is no problem on Intel Xeon 64-bit processor as I could test. Previous Comments: ------------------------------------------------------------------------ [2007-04-23 09:18:20] tony2001@php.net Not reproducible (both on 32bit and 64bit). ------------------------------------------------------------------------ [2007-04-22 18:44:55] petr dot stastny at centrum dot cz Sorry, it is converted to SIGNED int ------------------------------------------------------------------------ [2007-04-22 18:43:53] petr dot stastny at centrum dot cz The problem is that first 32 bits are set to 1 (not 0) in the output of unpack() function, thus it is interpreted as very large number and then converted to unsigned int for PHP representation. ------------------------------------------------------------------------ [2007-04-12 20:11:55] wez@php.net This isn't bogus, this is a real bug that causes pain. N is there for people writing code that talks to network services that need to convert numbers from network byte order to the native format. Also note that we get a bonus crash bug on 64-bit platforms too: $fail = '\x00\x00\x00\x8c'; $result = unpack('Nsize', $fail); $size = $result['size'] & 0xffffffff; // BANG! ------------------------------------------------------------------------ [2007-02-24 15:12:29] iliaa@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php You should be using either L or V, not N. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/40543 -- Edit this bug report at http://bugs.php.net/?id=40543&edit=1

« previous php.bugs (#111828) next »