mojira.dev
MC-107170

writeString method of PacketBuffer is not creating correct exception text

The bug

When a String whose encoded length is larger than 32767 bytes should be written to a PacketBuffer the message in the exception uses the length of the String instead of the length of the byte array. This results in exceptions like "String too big (was 16000 bytes encoded, max 32767)".

net.minecraft.network.PacketBuffer.writeString(String) (MCP 9.30, Minecraft 1.10)

public PacketBuffer writeString(String string)
{
    byte[] abyte = string.getBytes(Charsets.UTF_8);

    if (abyte.length > 32767)
    {
        // Replaced this, uses abyte.length instead of string.length()
        //throw new EncoderException("String too big (was " + string.length() + " bytes encoded, max " + 32767 + ")");
        throw new EncoderException("String too big (was " + abyte.length + " bytes encoded, max " + 32767 + ")");
    }
    else
    {
        this.writeVarIntToBuffer(abyte.length);
        this.writeBytes(abyte);
        return this;
    }
}

How to reproduce

See MC-68458

Linked issues

Comments 0

No comments.

marcono1234

Erik Broes

Unconfirmed

String, buffer, exception

Minecraft 1.10.2, Minecraft 16w38a

Minecraft 16w39a

Retrieved