Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uint32 numbers are incorrectly serialized on Windows #163

Open
bderleta opened this issue Dec 13, 2021 · 1 comment
Open

uint32 numbers are incorrectly serialized on Windows #163

bderleta opened this issue Dec 13, 2021 · 1 comment
Labels

Comments

@bderleta
Copy link

bderleta commented Dec 13, 2021

Seems related to issue #119, but occurs in serialization. Extension built from master branch just an hour before, but confirmed with 2.2.0RC1 and 2.1.2 PECL builds as well - all affected.

$payload = 3119646122;
$pack = msgpack_pack($payload);
print bin2hex($pack[0]) . "\r\n";
$unpack = msgpack_unpack($pack);
var_dump($unpack);

On linux builds:

ce
int(3119646122)

On windows builds (VS17 x64 TS):

d2
int(-1175321174)

msgpack_pack is producing incorrectly 0xD2 (signed int32) type specifier, so it is not an unpacker issue.

It seems it is caused by long being 4 byte, while zend_long is correctly 8 byte in size. Therefore, msgpack_pack_long accepting long argument is truncating zend_long value, then invokes msgpack_pack_real_int32 treating it as signed 32-bit value. The correct behavior is observed after replacing msgpack_pack_long by msgpack_pack_long_long in msgpack_serialize_zval:

 case IS_LONG:
            msgpack_pack_long_long(buf, zval_get_long(val_noref));
            break;
@m6w6
Copy link
Collaborator

m6w6 commented Dec 14, 2021

Thank you!
Looks like a LLP64 vs LP64 issue.

@m6w6 m6w6 added the bug label Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants