[php-src] Issue #9899: pack() 'Q' unsigned formatter returning negative values

From: Date: Mon, 07 Nov 2022 02:14:10 +0000
Subject: [php-src] Issue #9899: pack() 'Q' unsigned formatter returning negative values
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242759@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9899 Author: need-sleep ### Description The following code: ```php <?php // l signed long (always 32 bit, machine byte order) $packed = pack('l', -2147483500); $unpacked = unpack("l", $packed); var_dump($unpacked); // L unsigned long (always 32 bit, machine byte order) $packed = pack('L', -2147483500); $unpacked = unpack("L", $packed); var_dump($unpacked); // q signed long long (always 64 bit, machine byte order) $packed = pack('q', -2147483500); $unpacked = unpack("q", $packed); var_dump($unpacked); // Q unsigned long long (always 64 bit, machine byte order) $packed = pack('Q', -2147483500); $unpacked = unpack("Q", $packed); var_dump($unpacked); ?> ``` Resulted in this output (4th value is negative/signed): ```bash array(1) { [1]=> int(-2147483500) } array(1) { [1]=> int(2147483796) } array(1) { [1]=> int(-2147483500) } array(1) { [1]=> int(-2147483500) } ``` But I expected this output instead (4th value to be converted to unsigned): ```bash array(1) { [1]=> int(-2147483500) } array(1) { [1]=> int(2147483796) } array(1) { [1]=> int(-2147483500) } array(1) { [1]=> int(2147483796) } ``` Also tested on onecompiler [here](https://onecompiler.com/php/3yn7v2mqq) which claims to be latest version of PHP 7 ### PHP Version 8.1.2-1ubuntu2.6 ### Operating System Ubuntu 22.04.1 LTS 64-bit

« previous php.bugs (#242759) next »