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

MessagePack serialization is broken for negative integers #31

Open
Archie3d opened this issue Oct 20, 2022 · 0 comments
Open

MessagePack serialization is broken for negative integers #31

Archie3d opened this issue Oct 20, 2022 · 0 comments

Comments

@Archie3d
Copy link

Archie3d commented Oct 20, 2022

Hi 👋 ,
There are seem to be some unhandled cases in the MessagePack serializer:

  • fromData does not handle cases 0xd0, 0xd1, 0xd2, and 0xd3:
...
        else if (d == 0xd0)
        {
            return int(is.readByte());
        }
        else if (d == 0xd1)
        {
            return int(is.readShortBigEndian());
        }
        else if (d == 0xd2)
        {
            return is.readIntBigEndian();
        }
        else if (d == 0xd3)
        {
            return is.readInt64BigEndian();
        }
...
  • toData code reads
...
            else if (v >= 32768)
            {
                os.writeByte (char (0xd1));
                os.writeShortBigEndian (short (v));
            }
            else if (v >= 2147483648)
            {
                os.writeByte (char (0xd2));
                os.writeIntBigEndian (int (v));
            }
...

has to be

...
            else if (v >= -32768)
            {
                os.writeByte (char (0xd1));
                os.writeShortBigEndian (short (v));
            }
            else if (v >= -2147483648LL)
            {
                os.writeByte (char (0xd2));
                os.writeIntBigEndian (int (v));
            }
...
  • Also on line 167:
        else
        {
            os.writeByte (char (0xdc));
            os.writeIntBigEndian (n);
        }

must be

        else
        {
            os.writeByte (char (0xdd));
            os.writeIntBigEndian (n);
        }

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant