lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Nice idea with __gc !!!
> But unfortunately, "memory usage limiter" fails to stop this simple
> malicious one-liner until all available memory has been exhausted:
> 
> -- track memory use
> do
>   -- maximum memory (in KB) that can be used
>   local memlimit = 1000
>   local mt = {__gc = function (u)
>     if collectgarbage("count") > memlimit then
>       error("script uses too much memory")
>     else
>       setmetatable({}, getmetatable(u))
>     end
>   end}
>   setmetatable({}, mt)
> end
> 
> -- memory eater
> local t={}; while t do t[#t+1] = t end
> 
> 
> Nevertheless, it will be stopped by "CPU usage limiter".

So, we are still in the game :-)

Anyway, one way to improve this sandbox is to check memory in function
'step', too.

-- Roberto