From 5a54d098690d1c46a3dd56382928c75426c055cd Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 27 Apr 2023 13:18:28 +0100 Subject: [PATCH] InventoryManager: verify slot existence in locateWindowAndSlot() previously, this would happily return invalid slot IDs, potentially leading to a crash. --- src/network/mcpe/InventoryManager.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/network/mcpe/InventoryManager.php b/src/network/mcpe/InventoryManager.php index a651b9213..c6d83c65e 100644 --- a/src/network/mcpe/InventoryManager.php +++ b/src/network/mcpe/InventoryManager.php @@ -205,11 +205,13 @@ class InventoryManager{ if($entry === null){ return null; } + $inventory = $entry->getInventory(); $coreSlotId = $entry->mapNetToCore($netSlotId); - return $coreSlotId !== null ? [$entry->getInventory(), $coreSlotId] : null; + return $coreSlotId !== null && $inventory->slotExists($coreSlotId) ? [$inventory, $coreSlotId] : null; } - if(isset($this->networkIdToInventoryMap[$windowId])){ - return [$this->networkIdToInventoryMap[$windowId], $netSlotId]; + $inventory = $this->networkIdToInventoryMap[$windowId] ?? null; + if($inventory !== null && $inventory->slotExists($netSlotId)){ + return [$inventory, $netSlotId]; } return null; }