GVovkiv wrote: ↑Mon Aug 16, 2021 11:03 am
But what to do with infinity loops?
There are debug hooks as grump has mentioned, but they are only reliable if JIT is disabled; for example they don't work on compiled tail calls. So if you want to go that way, you need to disable the string metatable, disable JIT for the loaded chunk, and set up appropriate debug hooks to watch for OOM or infinite loops.
grump wrote: ↑Mon Aug 16, 2021 11:52 am
You could use pattern matching or debug hooks to mitigate those.
Lua patterns are a joke, far too powerless for proper tokenization of a Lua file. Imagine something like
Code: Select all
x = ("")["\109\97t\099h"](("")["r"..("")["c\104a\114"](101).."p"]("a",100),("")["r"..("")["c\104a\114"](101).."p"]("a\42",100).."b")
Debug hooks won't help if the infinite loop (actually finite but many years long) is in a C function like string.match().
I agree that in general, it's difficult to protect yourself against a specially crafted save file. But there are probably more attack vectors that I haven't considered beyond OOM and lockups. Don't underestimate the imagination and time spent by those with enough motivation.
For that reason, I advocate the use of non-Lua savefiles. They're much easier to protect in comparison. Granted, the existing serialization libraries are not written with security in mind, so they won't control things such as maximum memory used, therefore you will probably have to edit them to add those checks.