whueric / kryo

Automatically exported from code.google.com/p/kryo
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

StringSerializer decode error #3

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
StringSerializer's get() reads too much data from the buffer.

put() counts byte[]'s length, but get() reads char[length],
As some char is more then 1 byte(eg. chinese), it causes an error.

The fixed get() looks like:
    static public String get (final ByteBuffer buffer) {
        int length = IntSerializer.get(buffer, true);
        Context context = Kryo.getContext();
        byte[] bytes = (byte[])context.get("byteArray");
        if (bytes == null || bytes.length < length) {
            bytes = new byte[length];
            context.put("byteArray", bytes);
        }
        buffer.get(bytes, 0, length);
        return new String(bytes, 0, length, charset);
    }

Original issue reported on code.google.com by minwang...@gmail.com on 30 Oct 2009 at 11:53

GoogleCodeExporter commented 8 years ago
Hi, sorry I haven't responded sooner! I never got notification emails that 
issues had
been filed.

Do you have an example that fails? It looks like StringSerializer has changed 
since
you filed the bug and this may no longer be an issue.
http://code.google.com/p/kryo/source/browse/trunk/src/com/esotericsoftware/kryo/
serialize/StringSerializer.java#53

Original comment by nathan.s...@gmail.com on 6 Jan 2010 at 6:55

GoogleCodeExporter commented 8 years ago
I just fixed a related bug reported on the KryoNet project:
http://code.google.com/p/kryonet/issues/detail?id=1&can=1
I believe the StringSerializer will now work properly.

Original comment by nathan.s...@gmail.com on 6 Jan 2010 at 7:25