From abc9efeeb8cccb3e23c055414941fed4a9871b9a Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 6 Jun 2022 20:39:15 +0200 Subject: [PATCH] Harden deserialize workaround against unexpected input Otherwise it will stop working entirely soon when the serialization inside Minetest is reworked. This allows it to work at least in the cases where the original bug (LuaJIT register limit) doesn't apply. --- worldedit/serialization.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/worldedit/serialization.lua b/worldedit/serialization.lua index 0b3cc4b..4140e17 100644 --- a/worldedit/serialization.lua +++ b/worldedit/serialization.lua @@ -114,12 +114,15 @@ function worldedit.serialize(pos1, pos2) return LATEST_SERIALIZATION_HEADER .. result, count end --- Contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) --- by ChillCode, available under the MIT license. local function deserialize_workaround(content) local nodes if not minetest.global_exists("jit") then nodes = minetest.deserialize(content, true) + elseif not content:match("^%s*return%s*{") then + -- The data doesn't look like we expect it to so we can't apply the workaround. + -- hope for the best + minetest.log("warning", "WorldEdit: deserializing data but can't apply LuaJIT workaround") + nodes = minetest.deserialize(content, true) else -- XXX: This is a filthy hack that works surprisingly well -- in LuaJIT, `minetest.deserialize` will fail due to the register limit @@ -130,7 +133,7 @@ local function deserialize_workaround(content) local startpos, startpos1 = 1, 1 local endpos while true do -- go through each individual node entry (except the last) - startpos, endpos = escaped:find("},%s*{", startpos) + startpos, endpos = escaped:find("}%s*,%s*{", startpos) if not startpos then break end