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

Merchant trade select packet (C2S) does not check for negative indices

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 22w45a
    • 1.16.3, 21w03a, 1.16.5, 21w11a, 21w17a, 1.17 Pre-release 2, 1.17 Pre-release 3, 1.17 Pre-release 4, 1.17 Pre-release 5, 1.17 Release Candidate 1, 1.17 Release Candidate 2, 1.17, 1.17.1 Pre-release 1, 1.17.1 Pre-release 2, 1.17.1 Pre-release 3, 1.17.1, 21w44a, 1.19.2
    • None
    • Plausible
    • Networking
    • Low

      A merchant trade select packet sent from the client to the server is not checked for an index that is less than 0, only less than the size of the trade offer list. Because of this, sending a negative index such as -1 will cause an ArrayIndexOutOfBoundsException to be thrown and logged to the console.

      [12:00:00] [Server thread/FATAL] (Minecraft) Error executing task on Server
      java.lang.ArrayIndexOutOfBoundsException: null
      

      Code analysis (Yarn mappings):

      public void onMerchantTradeSelect(SelectMerchantTradeC2SPacket packet) {
      	NetworkThreadUtils.forceMainThread(packet, this, (ServerWorld) this.player.getServerWorld());
      	int tradeId = packet.getTradeId();
      
      	ScreenHandler screenHandler = this.player.currentScreenHandler;
      	if (screenHandler instanceof MerchantScreenHandler) {
      		MerchantScreenHandler merchantScreenHandler = (MerchantScreenHandler) screenHandler;
      		
      		// Check for i >= 0 before calling the screen handler method(s)
      		merchantScreenHandler.setRecipeIndex(tradeId);
      		merchantScreenHandler.switchTo(tradeId);
      	}
      }
      

            gegy1000 [Mojang] Gegy
            haykam haykam
            Votes:
            18 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: