FigBug/Gin

MessagePack serialization is broken for negative integers

Archie3d opened this issue ยท 0 comments

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!