Skip to content

Commit

Permalink
Luacontroller: Revert function stripping from digiline messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeija committed Jan 15, 2017
1 parent c2e3d7c commit 54daee2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
18 changes: 0 additions & 18 deletions mesecons/util.lua
Expand Up @@ -151,24 +151,6 @@ function mesecon.tablecopy(table) -- deep table copy
return newtable
end
function mesecon.tablecopy_stripfunctions(table) -- deep table copy, but remove all functions
if type(table) == "function" then return nil end -- functions become nil
if type(table) ~= "table" then return table end -- no need to copy
local newtable = {}
for idx, item in pairs(table) do
if type(idx) ~= "function" then
if type(item) == "table" then
newtable[idx] = mesecon.tablecopy_stripfunctions(item)
elseif type(item) ~= "function" then
newtable[idx] = item
end
end
end
return newtable
end
function mesecon.cmpAny(t1, t2)
if type(t1) ~= type(t2) then return false end
if type(t1) ~= "table" and type(t2) ~= "table" then return t1 == t2 end
Expand Down
8 changes: 5 additions & 3 deletions mesecons_luacontroller/init.lua
Expand Up @@ -278,9 +278,11 @@ local function get_digiline_send(pos)
return false
end

-- No sending functions over the wire and make sure serialized version
-- of the data is not insanely long to prevent DoS-like attacks
msg = mesecon.tablecopy_stripfunctions(msg)
-- It is technically possible to send functions over the wire since
-- the high performance impact of stripping those from the data has
-- been decided to not be worth the added realism.
-- Make sure serialized version of the data is not insanely long to
-- prevent DoS-like attacks
local msg_ser = minetest.serialize(msg)

This comment has been minimized.

Copy link
@numberZero

numberZero Jan 15, 2017

Contributor

Doesn’t this impact performance too? Serialization should take even more time than mere copying. I could write a function that measures (approximately, like this solution) memory usage in a similar way, just not creating the resulting string; that should be significantly faster (if that is necessary).

This comment has been minimized.

Copy link
@Jeija

Jeija Jan 16, 2017

Author Collaborator

Yes, this propably also impacts performance, but having some kind of size restriction is non-negotiable. If you could write a function that does some approximation on memory usage (we only care about string length and number of table entries here) that is provably faster, then I'd be happy to use that instead 👍 . That function should propably live in mesecons/util.lua since we might need this somewhere else and it is not really luacontroller-specific.

if #msg_ser > mesecon.setting("luacontroller_digiline_maxlen", 50000) then
return false
Expand Down

0 comments on commit 54daee2

Please sign in to comment.