From ffae69471d39e28abf9a2c2960397bf76abdd68e Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Mon, 8 Mar 2021 18:13:26 -0500 Subject: [PATCH] Add protection for out-of-bounds inventory management --- .../java/org/geysermc/connector/inventory/Inventory.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java b/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java index 9246c0478..11a0034ad 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java @@ -30,6 +30,7 @@ import com.nukkitx.math.vector.Vector3i; import lombok.Getter; import lombok.NonNull; import lombok.Setter; +import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; import java.util.Arrays; @@ -86,10 +87,18 @@ public class Inventory { } public GeyserItemStack getItem(int slot) { + if (slot > this.size) { + GeyserConnector.getInstance().getLogger().debug("Tried to get an item out of bounds! " + this.toString()); + return GeyserItemStack.EMPTY; + } return items[slot]; } public void setItem(int slot, @NonNull GeyserItemStack newItem, GeyserSession session) { + if (slot > this.size) { + session.getConnector().getLogger().debug("Tried to set an item out of bounds! " + this.toString()); + return; + } GeyserItemStack oldItem = items[slot]; updateItemNetId(oldItem, newItem, session); items[slot] = newItem;