ID:               47564
 Updated by:       il...@php.net
 Reported By:      laacz at laacz dot lv
-Status:           Open
+Status:           Closed
 Bug Type:         Strings related
 Operating System: FreeBSD 6.1-STABLE (amd64)
 PHP Version:      5.2.9
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------

[2009-04-14 14:12:00] vivekanandan8 at yahoo dot com

Hi,
   for signed long also work properly,please use code below. 

v |= php_unpack(&input[inputpos], 4, issigned, map);
if (sizeof(long) > 4) {
   if( type == 'l' ) {
      v = (signed int) v; 
   }else{ 
       v = (unsigned int) v;
   }
}

Full Source Code: 

http://www.gnudeveloper.com/software/php-5.3/pack.c


Regards,
vivekanandan.

------------------------------------------------------------------------

[2009-04-10 11:07:27] vivekanandan8 at yahoo dot com

Hi,
    Regarding the bug fix, This is tested in Version PHP 5.3 and works
fine,for any one needs full source code :   
http://www.gnudeveloper.com/software/php/pack.c

Regards,
vivekanandan.

------------------------------------------------------------------------

[2009-04-10 10:46:57] vivekanandan8 at yahoo dot com

Hi,
   Generally the Zend engine holds any variable as  zval which holds
the integer as long data type only. 

32 bit Platform: long         => 4 byte = 32 bit 
64 bit Platform: long         => 8 byte = 64 bit
64 bit Platform: unsigned int => 4 byte = 32 bit

Hence in the 64 bit platform, we have to convert from long to unsigned
int only in 64 bit Platform.
Hence in php source  php5.3-200903301230/ext/standard/pack.c
In PHP_FUNCTION(unpack) place, add this convertion immediate
after  php_unpack function as folows. 

v |= php_unpack(&input[inputpos], 4, issigned, map);
if (sizeof(long) > 4) { v = (unsigned int) v; }


I tested in both 32 & 64 bit platform ,it works fine , please close
this Bug
Regards,
vivekanandan

------------------------------------------------------------------------

[2009-03-04 16:43:21] laacz at laacz dot lv

Description:
------------
Unpacking unsigned long (32bit; always big endian; "N") on 64bit 
system returns 64bit signed int instead of 32bit.

You can do & 0xffffffff on unpacked value, and get desired result, 
but that's still a bug.

Reproduce code:
---------------
<?php
list(,$command_id) =  unpack('N', chr(0x80) . chr(0x00) . chr(0x00) .
chr(0x09));
echo hexdec(dechex($command_id)) . "\n0x" . dechex($command_id) .
"\n";
?>



Expected result:
----------------
2147483657
0x80000009





Actual result:
--------------
1.8446744071562E+19
0xffffffff80000009






------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=47564&edit=1

Reply via email to