mojira.dev
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);
	}
}

Comments 8

           

 
 

          
                                                     
                                 .''.
       .''.             *''*    :_\/_:     . 
      :_\/_:   .    .:.*_\/_*   : /\ :  .'.:.'.
  .''.: /\ : _\(/_  ':'* /\ *  : '..'.  -=:o:=-
 :_\/_:'.:::. /)\*''*  .|.* '.\'/.'_\(/_'.':'.'
 : /\ : :::::  '*_\/_* | |  -= o =- /)\    '  *
  '..'  ':::'   * /\ * |'|  .'/.\'.  '._____
      *        __*..* |  |     :      |.   |' .---"|
       _*   .-'   '-. |  |     .--'|  ||   | _|    |
    .-'|  _.|  |    ||   '-__  |   |  |    ||      |
    |' | |.    |    ||       | |   |  |    ||      |
 ___|  '-'     '    ""       '-'   '-.'    '`      |____

🎉 Minecraft's had over 200K reported bugs now; congrats?

Please keep messages such as these in the dedicated Mojira subreddit post: https://www.reddit.com/r/Mojira/comments/iqitfw/the_minecraft_java_edition_bug_tracker_has_just/

Thanks 🙂

Only MC-2 and MC-20 were valid bugs, MC-200, MC-2000 and MC-20000 weren't valid

Any further comments that are not related to the bug will be removed - don't get me wrong, I agree with the sentiment - but we have a separated Reddit post for this which I linked above. Thanks!

Can someone help me understand the issue to attempt to reproduce?

@@unknown, this is about the packet ServerboundSelectTradePacket (1.16.3, Mojang name), correct?
And after the exception was logged by the server the connection is closed, right? Though the server-side validation of packets should probably be improved nonetheless.

haykam

gegy

Plausible

Low

Networking

1.16.3, 21w03a, 1.16.5, 21w11a, 21w17a, ..., 1.17.1 Pre-release 2, 1.17.1 Pre-release 3, 1.17.1, 21w44a, 1.19.2

22w45a

Retrieved