]> git.lizzy.rs Git - worldedit.git/blobdiff - worldedit/serialization.lua
Harden deserialize workaround against unexpected input
[worldedit.git] / worldedit / serialization.lua
index 0b3cc4b5007476168055c385b141e32fa4d6c2c2..4140e171f496e5dec2d262dc5d5fdd04e9ff64f8 100644 (file)
@@ -114,12 +114,15 @@ function worldedit.serialize(pos1, pos2)
        return LATEST_SERIALIZATION_HEADER .. result, count\r
 end\r
 \r
--- Contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile)\r
--- by ChillCode, available under the MIT license.\r
 local function deserialize_workaround(content)\r
        local nodes\r
        if not minetest.global_exists("jit") then\r
                nodes = minetest.deserialize(content, true)\r
+       elseif not content:match("^%s*return%s*{") then\r
+               -- The data doesn't look like we expect it to so we can't apply the workaround.\r
+               -- hope for the best\r
+               minetest.log("warning", "WorldEdit: deserializing data but can't apply LuaJIT workaround")\r
+               nodes = minetest.deserialize(content, true)\r
        else\r
                -- XXX: This is a filthy hack that works surprisingly well\r
                -- in LuaJIT, `minetest.deserialize` will fail due to the register limit\r
@@ -130,7 +133,7 @@ local function deserialize_workaround(content)
                local startpos, startpos1 = 1, 1\r
                local endpos\r
                while true do -- go through each individual node entry (except the last)\r
-                       startpos, endpos = escaped:find("},%s*{", startpos)\r
+                       startpos, endpos = escaped:find("}%s*,%s*{", startpos)\r
                        if not startpos then\r
                                break\r
                        end\r