Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion msgpack_unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ int msgpack_unserialize_uint64(msgpack_unpack_data *unpack, uint64_t data, zval

if (data <= (uint64_t) ZEND_LONG_MAX) {
ZVAL_LONG(*obj, data);
} else if (data <= 1L<<52) {
} else if (data <= (uint64_t) 1 << 52) {
ZVAL_DOUBLE(*obj, data);
} else {
char buf[0x20] = {0}, *ptr = print_u64_to_buf(&buf[sizeof(buf)-1], data);
Expand Down
24 changes: 24 additions & 0 deletions tests/issue067_32bit_double.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Issue #67 (uint64_t above ZEND_LONG_MAX up to 2^52 unpacks as float on 32-bit)
--SKIPIF--
<?php
if (!extension_loaded("msgpack")) {
die("skip");
}
if (PHP_INT_SIZE !== 4)
die("skip this test is for 32-bit platforms only");
?>
--FILE--
<?php
var_dump(msgpack_unpack("\xcf"."\x00\x00\x00\x00"."\x80\x00\x00\x00")); // 2^31
var_dump(msgpack_unpack("\xcf"."\x00\x00\x00\x01"."\x00\x00\x00\x00")); // 2^32
var_dump(msgpack_unpack("\xcf"."\x00\x10\x00\x00"."\x00\x00\x00\x00")); // 2^52
var_dump(msgpack_unpack("\xcf"."\x00\x10\x00\x00"."\x00\x00\x00\x01")); // 2^52 + 1
?>
OK
--EXPECT--
float(2147483648)
float(4294967296)
float(4503599627370496)
string(16) "4503599627370497"
OK
Loading