Skip to content

PlayerInventory#setItem check for slot outside of inventory#11397

Closed
strainxx wants to merge 0 commit into
PaperMC:masterfrom
strainxx:fix-setitem-slot-check
Closed

PlayerInventory#setItem check for slot outside of inventory#11397
strainxx wants to merge 0 commit into
PaperMC:masterfrom
strainxx:fix-setitem-slot-check

Conversation

@strainxx
Copy link
Copy Markdown
Contributor

fixes #11391
Now if setItem is < 0 or > 40 it will throw ArrayIndexOutOfBoundsException

@strainxx strainxx requested a review from a team as a code owner September 13, 2024 21:19
+ if (index < 0 || index > 40) {
+ throw new ArrayIndexOutOfBoundsException("Index must be between 0 and 40");
+ }
+ // Paper end - Validate setItem index
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check should be done in CraftInventoryPlayer#setItem and not the super method. we could also modify the underlying nms method to set the item regardless of whether it is inbounds however that might confuse plugin developers as the player inventory is split into compartments and the index and size displayed in the exception will not match the slot input by the dev.

@strainxx strainxx force-pushed the fix-setitem-slot-check branch from 3adae82 to 73b2423 Compare September 14, 2024 10:00
@strainxx strainxx closed this Sep 14, 2024
@strainxx strainxx force-pushed the fix-setitem-slot-check branch from 73b2423 to 4ff58c4 Compare September 14, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

PlayerInventory#setItem doesn't check for slot outside of inventory

2 participants