简体   繁体   English

在Lua中处理StackOverflowException

[英]Handling StackOverflowException in Lua

I'm making an IRC bot in C#, and want to have Lua be executable via a command. 我正在用C#开发IRC机器人,并希望通过命令可执行Lua。 I already have this working, and have overcome some basic obstacles, but now I'm having a larger problem with a StackOverflowException; 我已经在进行这项工作,并且已经克服了一些基本的障碍,但是现在我遇到了一个更大的StackOverflowException问题; My friend gave me some Lua code to run, which every time seems to cause a StackOverflowException, no matter how hard I try to prevent it. 我的朋友给了我一些要运行的Lua代码,无论我多么努力地阻止它,每次似乎都会引起StackOverflowException。

print(string.find(string.rep("a", 2^20), string.rep(".?", 2^20)))

So, with this being executed using LuaInterface (LuaInterface 2.0.0.16708 to be precise) - I get a StackOverflowException in my code and I don't seem to be able to fix this, looking at some previous questions. 因此,使用LuaInterface(准确地说是LuaInterface 2.0.0.16708)执行此操作后,我的代码中出现了StackOverflowException,而我似乎无法解决此问题,请看一下先前的问题。

I know parsing code before executing it to predict stack overflows is hard, so I don't know how I would circumvent this. 我知道在执行代码之前很难解析代码以预测堆栈溢出,因此我不知道该如何规避。 I have already tried multi-threading (which solved a previous problem where yielding code wouldn't return control back to C#) but this does not seem to help. 我已经尝试过多线程(它解决了先前的问题,在该问题中,屈服代码不会将控制权返回给C#),但这似乎无济于事。

To get around that particular error use Lua 5.2.2 or newer. 要解决该特定错误,请使用Lua 5.2.2或更高版本。 The case is a reported bug that got fixed in the version 5.2.2. 该案例是一个已报告的错误 ,已在5.2.2版中修复。 It gives "pattern too complex" error instead. 相反,它给出“模式太复杂”错误。

And as far as sandboxing is concered why not fashion it after the Lua live demo as suggested in this SO answer ? 而就沙盒而言,为什么不按照这个SO答案中的建议在Lua live demo之后制作它呢? I don't know how secure it is but I'd presume the authors have both the incentive and capability of making it as secure as possible. 我不知道它有多安全,但我想作者既有动力又有能力使它尽可能地安全。 The sources can be found from here . 来源可以从这里找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM