From 54897c1447890327772771f631bed7fc90b7b486 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 8 Jun 2022 22:26:08 +0200 Subject: [PATCH] Fix deserializing to a smaller inventory Void excess slots when deserializing an inventory to a target that has fewer slots than what was serialized. This fixs inventory sync failing when a stored inventory has trash slots in use but the player does not have the slots unlocked. --- packages/slave/modules/clusterio/serialize.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/slave/modules/clusterio/serialize.lua b/packages/slave/modules/clusterio/serialize.lua index f9a77da0..b03557cf 100644 --- a/packages/slave/modules/clusterio/serialize.lua +++ b/packages/slave/modules/clusterio/serialize.lua @@ -281,8 +281,11 @@ function serialize.deserialize_inventory(inventory, serialized) local repeat_count = entry.r or 0 for offset = 0, repeat_count do - -- XXX what if the inventory is smaller on this instance? local index = base_index + offset + if index > #inventory then + print("Error: Inventory index out of bounds deserializing inventory, voiding excess slots") + break + end local slot = inventory[index] if entry.f then local call_success, call_return = pcall(inventory.set_filter, index, entry.f)