InventoryManager: verify slot existence in locateWindowAndSlot()

previously, this would happily return invalid slot IDs, potentially leading to a crash.
This commit is contained in:
Dylan K. Taylor 2023-04-27 13:18:28 +01:00
parent 1d10107024
commit 5a54d09869
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

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