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 0
No comments.