Bug #72315 [Opn->Nab]: Unpack 'J' & 'P' doesn't produce expected results

From: Date: Thu, 02 Jun 2016 11:20:31 +0000
Subject: Bug #72315 [Opn->Nab]: Unpack 'J' & 'P' doesn't produce expected results
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201404@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72315&edit=1 ID: 72315 Updated by: requinix@php.net Reported by: ads at tristanleboss dot net Summary: Unpack 'J' & 'P' doesn't produce expected results -Status: Open +Status: Not a bug Type: Bug Package: *Math Functions Operating System: Windows 7 x64 PHP Version: 7.0.7 Block user comment: N Private report: N New Comment: 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 There's a yellow Caution note on the docs page that says PHP uses signed ints, so if you unpack() a large enough number you'll get one signed even if you asked for unsigned. And your two numbers (10e18 and 13e18) are beyond the limit of a signed integer (PHP_INT_MAX=9e18). Previous Comments: ------------------------------------------------------------------------ [2016-06-02 10:57:27] ads at tristanleboss dot net Package: Math functions ------------------------------------------------------------------------ [2016-06-02 10:56:46] ads at tristanleboss dot net Description: ------------ Hello, While doing some tests, I discovered the 'P' format (unsigned long long (always 64 bit, little endian byte order)) and the 'J' format (unsigned long long (always 64 bit, big endian byte order)) are not giving the expected results on my Windows 7 x64 test machine with PHP 7.0.7RC1. Indeed, they don't account for the "unsigned" nature and output the signed version. Indeed: unpack('P', "\xC0\x00\xF8\x90\x32\x04\x00\x90") will output "-8070445917020880704". The expected result is "13835331353480265872". unpack('J', "\xC0\x00\xF8\x90\x32\x04\x00\x90") will output "-4611412720229285744". The expected result is "10376298156688670912". No error/warning message will be displayed. Test script: --------------- <?php var_dump( unpack('P', "\xC0\x00\xF8\x90\x32\x04\x00\x90") ); var_dump( unpack('J', "\xC0\x00\xF8\x90\x32\x04\x00\x90") ); Expected result: ---------------- array(1) { [1]=> int(13835331353480265872) } array(1) { [1]=> int(10376298156688670912) } Actual result: -------------- array(1) { [1]=> int(-8070445917020880704) } array(1) { [1]=> int(-4611412720229285744) } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72315&edit=1

« previous php.bugs (#201404) next »