Mojira Archive
MC-200000

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

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

Fixed

haykam

[Mojang] Gegy

2020-09-11, 05:48 AM

2022-11-08, 03:25 PM

2022-11-08, 03:25 PM

18

13

Plausible

Low

Networking

1.16.3 - 1.19.21.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

22w45a