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

IndexOutOfBoundsException occurs instead of a "Bad packet id" message


    • Icon: Bug Bug
    • Resolution: Fixed
    • 24w03a
    • 19w34a, 1.16.5, 21w11a
    • None
    • Confirmed
    • Networking

      When a packet with an invalid ID is received, an IndexOutOfBoundsException occurs instead of a "Bad packet id" message. For instance, instead of "Internal Exception: io.netty.handler.codec.DecoderException: java.io.IOException: Bad packet id 42", the message is "Internal Exception: io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException: Index 42, Size: 5". When combined with MC-134498, it is very difficult to tell whether the issue is with the implementation of the packet or with something else. This is only really an issue for people implementing custom servers; it shouldn't affect regular gameplay (apart from randomly corrupt packets, in which case the exact error message doesn't really matter).

      The following Python code should replicate the issue:

      import socket
      import time
      serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      serversocket.bind(('', 1234))
      (clientsocket, address) = serversocket.accept()
      clientsocket.sendall(bytes([1, 42]))  # Invalid packet, length 1, packet ID 42, no further payload

      Test by connecting to localhost:1234; in current versions, this will result in an IndexOutOfBoundsException.

      An example stacktrace from 1.16.5 in the wild: https://pastebin.com/a5FFYicS

      This issue was first introduced in 19w34a (the first 1.15 snapshot); it did not occur in 1.14.4. This version created ConnectionProtocol$PacketSet; the idToConstructor field is not bounds-checked in createPacket, so an exception is thrown instead of returning null (prior versions used an Object2IntMap, which would have returned null). Note also that the code that creates the Bad packet id message still exists and should still run if the bounds-check is re-added.

            Unassigned Unassigned
            pokechu22 [Mod] Pokechu22
            3 Vote for this issue
            2 Start watching this issue