Handling StackOverflowException in Lua - c#

I'm making an IRC bot in C#, and want to have Lua be executable via a command. I already have this working, and have overcome some basic obstacles, but now I'm having a larger problem with a 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.
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.
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.

To get around that particular error use Lua 5.2.2 or newer. The case is a reported bug that got fixed in the version 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? 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.

Related

How to execute Go function in C#

Is there any way to execute a Go function from C#? For Python I would use Ironpython for example.
I know that I could spawn a process to execute a Go script, but I don't really want to fallback to such a solution, if possible.
A Google search didn't reveal anything, so is there any way to do that using an API? Or do I have to fallback on processes?
I think Frank's answer is not right! Golang supports many build mode, and one is c-shared mode, it means you can use it like a c module.
e.g:
https://www.trs.ai/c%E8%B0%83%E7%94%A8golang%E4%BB%A3%E7%A0%81/
EDIT: my answer is now not true, since Go has been updated since I posted. this stackoverflow thread will help you solve your problem.
ORIGINAL ANSWER:
I don't think you're going to have much luck finding what you're looking for. Go is statically linked and C# doesn't support that.
From C#, calling a pre-compiled executable and reading the output is the easiest thing I can think of.
you can use grpc implement calls
grpc works across languages and platforms

"URI formats are not supported." exception just started showing up in really old, unchanged code

Ok, I'm experiencing a truly random bug and I cannot find any reason why this would happen. I have an application that I update that was first developed MANY years ago. I work on a sizable dev team whose sole responsibility is to manage this application and we've come to accept that the project is a bit of a "franken-code" project. We are but humble developers in a line of many generations of developers who've inherited this project. (This will be important to know later.)
There is a portion of our application that deep within the initialization process calls the following code:
string strPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
string strFile = strPath.Substring(6) + "\\" + FILE_NAME;
Here's the deal. My fellow team members, and myself, have been able to modify and build higher-level, UI and DB related sections of our solution for an eternity. I, nor anyone else, has modified the above code, or any code in the same code file (or project within the solution, for that matter.)
However, today while working in a completely different section of my application I began to get some really odd "Out of Memory" exception errors. I'm not sure if that relates to my problem but I felt it was worth mentioning that after rebooting my machine and reloading the VS solution, I'm now consistently getting the following exception when I attempt to run a debugger test, when the initialization process attempts to execute the above mentioned snippet of code:
Exception: A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
Message: URI formats are not supported.
I've googled this error message and it looks like the original dev was simply doing this wrong. This seems to be a common error, but what baffles me is that this has never been a problem until, randomly, today.
I know this is an odd question, but is there a way to fix this without modifying this code. As I mentioned, this is a really complex application that often feels a bit cobbled together. Our team is attempting to clean up, or replace, much of the applications functionality but there are portions we simply do not touch because we have no solid clue how the application will work once it is deployed to our production environment. This is a highly-critical application and it cannot be broken.
Might anyone have any clue what may cause this to "magically" start happening? Especially since I have been working in UI-related code, and no where near the low-level, configuration resolution section of code where this came from.
ADDITIONAL NOTES
We use source control. If I download, build an run an older revision of the application, it works.
We use AnkhSVN and when I inspect my changed files, again, there is nothing that has been changed that relates to the code that is now failing.
No one else in my team has ever seen this.
To my knowledge, I've not tweaked any setting associated with my project. I've taken a look at my project properties and everything looks normal. I guess there is a chance that I've hit some odd key-combo and enabled/disabled something through shortcut-keys, but I have no clue what that might be.
Any help is appreciated. Sorry for the novel. I'm just stumped and I'd rather not use a different method for acquiring this path string if there is ANY chance that altering this process could behave differently in different user environments.
I can only assume some working file within the Visual Studio that is associated with the project/solution had become corrupt. I searched through the text of my project files, and all of my code, and I didn't see anything out of place.
As I mentioned, we use source control. To attempt a fix, I pulled down the same source revision that I initially pulled for my current task. I compiled and ran the application. Everything worked properly in its "vanilla" state.
Next, I copied in all of the files I knew I had modified. I hadn't added any new project references or resources, so I just copied over the modified .cs files. I built and ran the application and I've had no trouble since the pull from my branch.
This does not answer the question of why this occurred, but this method can provide a solution to the problem.
I can confirm this change in Path.GetDirectoryName occured to me after installing VS 2015 and rebuilding our project in it so it seams to be .NET 4.6 feature.
Rebuilding the project again in VS 2013 returns the previous behaviour where Assembly.CodeBase with "file:" prefix is acceptable by Path.GetDirectoryName without any exception.
But rereading the MSDN documentation, there is a statement that "file:" paths are not supported, but this is not mentioned in ArgumentException thrown in VS 2015 code.
First of all, find out how many versions ago this started occuring: start with the current version, and work back changeset by changeset until it no longer fails.
It sounds like, for whatever reason, System.Reflection.Assembly.GetExecutingAssembly().CodeBase now returns a string that GetDirectoryName doesn't like. So, check the project files, the .sln, the repo config, anything that could cause a file to be in a different location.
If you can't find anything there, check the other files from that same commit, even if they appear that they shouldn't be related.
First Chance Exceptions generally happen when you've got multiple threads happening, so check for new threads that weren't in the previous version. I've also had situations where First Chance exceptions would only get caught under certain situations, and are silently ignored otherwise, so look changes in Debug settings: it's possible that this problem has always existed, you just haven't had the right settings to catch it until now.
Remember that under a source control, other people can change things that are "yours", even if only by accident.

ASP.NET MVC, outputting source code in error

So I've wound up in a very odd place. Due to circumstances beyond my control, a machine burned up before I was able to commit certain changes to a backup/repository. This is only one file that didn't get backed up, but it was an important one to me nonetheless.
However the binary that was generated still lives on an internal test webpage. So my first thought was to try a decompiler, which has given some results, but it isn't very accurate.
I noticed that when I do not have much configured for ASP.NET MVC, errors show the source code of the file that threw an exception if there is no kind of handling.
I was wondering if I might be able to use this to get my code back, but the output length seems limited to 9 lines.
So.
(A) is this possible?
(B) is there any way to get more than 9 lines?
(C) are there any good tools for this kind of thing?
I am not trying to hack. I own the site, and the code. It is just an unfortunate situation.
I think you are talking about PDB files. There's a question about it: Obtaining information about executable code from exe/pdb
You can inspect with http://www.codeproject.com/Articles/37456/How-To-Inspect-the-Content-of-a-Program-Database-P but it only shows little information.
And as you can read in http://www.wintellect.com/CS/blogs/jrobbins/archive/2009/05/11/pdb-files-what-every-developer-must-know.aspx
The actual file format of a PDB file is a closely guarded secret but Microsoft provides APIs to return the data for debuggers.

Running CPython functions from C#

I'm working on a project where I need to be able to run a python function that depends on SciPy/NumPy. Due to this being an add-on to a project already in progress, using IronPython would not be an option.
Additional info:
Python.NET seemed to be a good fit, but I was unable to get the return value from RunString() (it would only return NULL).
Passing arguments and catching the return value (a tuple) is necessary.
The function is in a statistical package that was created by a support group for the team, so modification of that would also not be possible.
I'm at quite a loss for what to do. Any hints in the right direction are appreciated. Thanks for any help you can give!
I understand that this may be quite vague, but I cannot give explicit details to the project. If any clarification is needed please let me know and I'll do my best!
I guess you could write a DLL that uses the CPython API to expose the function, then call it in C#?
It's possible to embed the Python interpreter; although I've never done this personally, I guess it would be useful: http://docs.python.org/extending/embedding.html
Does it need to be portable beyond Windows? If not, perhaps you can embed the CPython interpreter with C++/CLI, wrap that in a nice .Net-ish interface and use the resulting code from C#. Never tried that, so I don't know if it's going to work.
Regardless if you go through this route or the 'write a native DLL' route, it will probably be easier to to embed python using Boost.Python, though I'm not sure if your wrapper code enough is going to be large enough to make all of this (compiling the Boost behemoth, learning Boost.Python, making sure it works with C++/CLR, increasing your target file size) worth it.
IronPython using DLR might be the way to go. Mind you it won't be the fastest way, but it seems like something worth pursuing if you're going to do this a lot. Another useful link
The ironclad project was started to allow using CPython extensions from IronPython, especially SciPy/NumPy it seems. I don't know how usable it is (and how actively it is still being developed)

Migrating C# code from Cassandra .5 to .6

I have some some simple code derived from an example that is meant to form a quick write to the Cassandra db, then loop back and read all current entries, everything worked fine. When .6 came out, i upgraded Cassandra and thrift, which threw errors in my code (www[dot]copypastecode[dot]com/26760/) - i was able to iron out the errors by converting the necessary types, however in the version that compiles now only seems to read one item back, im not sure if its not saving db changes or if its only reading back 1 entry. the "fixed" code is here: http://www.copypastecode.com/26752/. Any help would be greatly appreciated.
First of all, let me say that you should definitly use TBufferedStream instead of TSocket for the TBinaryProtocol, that will make a huge impact on your application performance.
For the Apache Thrift API documentation that BATCH_INSERT methods is deprecated, so it could have introduced a misleading bug on that operation that actually only insert the first column. Said so, why don't you try to use BATCH_MUTATE instead?
By the way, why are you trying to use Thrift directly? There are some nice c# clients for Cassandra that are actually performing really well. You can find the whole list at http://wiki.apache.org/cassandra/ClientOptions.
I'm the author of one of them are is pretty much updated with Apache and its being used by some companies on production environment. Take a look at my homepage.

Categories

Resources