Skip to content

Integer overflow on a 64-bit system #67

@rybakit

Description

@rybakit

Unpacking 64-bit unsigned integer will result in a negative value if the value is bigger than 2^63 (as PHP does not support unsigned integers):

php > var_dump(msgpack_unpack("\xcf"."\xff\xff\xff\xff"."\xff\xff\xff\xff"));
int(-1)

But PHP's behavior in such cases is to fall back to float/double:

If PHP encounters a number beyond the bounds of the integer type, it will be interpreted as a float instead. Also, an operation which results in a number beyond the bounds of the integer type will return a float instead.

php > var_dump(PHP_INT_MAX + 1);
double(9.2233720368548E+18)
php > var_dump(hexdec('ffffffff'.'ffffffff'));
double(1.844674407371E+19)

I wonder if it would be reasonable to get msgpack_unpack() in line with PHP engine? Or return a string representation of the value?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions