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

QueryThreadGs4 can crash when incorrectly trying to use cached rules response

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.15.1
    • None
    • Plausible
    • Crash, Networking
    • Normal
    • Platform

      The bug

      net.minecraft.server.rcon.thread.QueryThreadGs4 (Mojang name) can crash because it can incorrectly try to use a cached rules response even though there hasn't been one created yet.

      The class is intended to cache rules responses and only generate new ones every 5 seconds. The problem is that the field used for this (lastRulesResponse) is initialized to 0 and the check whether the cached response should be used looks like this:

      private byte[] buildRuleResponse(DatagramPacket datagramPacket) throws IOException {
          String[] arrstring;
          long l = Util.getMillis();
          if (l < this.lastRulesResponse + 5000L) {
              byte[] arrby = this.rulesResponse.toByteArray();
              byte[] arrby2 = this.getIdentBytes(datagramPacket.getSocketAddress());
              arrby[1] = arrby2[0];
              arrby[2] = arrby2[1];
              arrby[3] = arrby2[2];
              arrby[4] = arrby2[3];
              return arrby;
          }
          this.lastRulesResponse = l;
          this.rulesResponse.reset();
          ...
      }
      

      Util.getMillis() calls in the end System.nanoTime() which can return negative values so the method above would use the empty byte array of rulesResponse and an ArrayIndexOutOfBoundsException would be thrown.

            Unassigned Unassigned
            marcono1234 [Mod] Marcono1234
            Votes:
            4 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              CHK: