mojira.dev
MC-270327

RCON client can send packets with packet size larger than 4096 bytes

The bug

The Minecraft implementation of the RCON client splits a long message based on the number of UTF-16 code units and converts them to UTF-8 before sending. This can result in increased byte lengths of up to 12288 (4096*3) bytes after conversion to UTF-8, which violates the RCON specification:
— The maximum possible value of packet size is 4096. If the response is too large to fit into one packet, it will be split and sent as multiple packets.

Code analysis

net/minecraft/server/rcon/thread/RconClient.java

private void sendCmdResponse(int id, String body) throws IOException {
    int length = body.length();

    do {
        int splitLength = 4096 <= length ? 4096 : length;
        this.send(id, 0, body.substring(0, splitLength));
        body = body.substring(splitLength);
        length = body.length();
    } while(0 != length);
}

private void send(int id, int type, String body) throws IOException {
    ByteArrayOutputStream bao = new ByteArrayOutputStream(1248);
    DataOutputStream out = new DataOutputStream(bao);
    byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
    out.writeInt(Integer.reverseBytes(bytes.length + 10));
    out.writeInt(Integer.reverseBytes(id));
    out.writeInt(Integer.reverseBytes(type));
    out.write(bytes);
    out.write(0);
    out.write(0);
    this.client.getOutputStream().write(bao.toByteArray());
}

Comments 1

Can confirm in 26.3 and 26.4 snapshot 10.

intsuc

(Unassigned)

Community Consensus

Platform

Normal

Networking

1.20.4, 24w14a, 1.21, 1.21.4, 25w04a, 1.21.5, 25w16a, 26.3, 26.4 Snapshot 10

Retrieved