Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-270327

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.20.4, 24w14a, 1.21, 1.21.4, 25w04a
    • None
    • Plausible
    • Networking
    • Normal
    • Platform

      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());
      }
      

            Unassigned Unassigned
            intsuc intsuc
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              CHK: