Skip to content

Loading and running bytecode #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
elice02 opened this issue Aug 16, 2019 · 4 comments
Closed

Loading and running bytecode #145

elice02 opened this issue Aug 16, 2019 · 4 comments

Comments

@elice02
Copy link

elice02 commented Aug 16, 2019

Hi,

I have been trying to run some bytecode using this:

let mut f = File::open("C:\Users\kkp\Documents\Rust\server_host\src\out.luac").unwrap();
let mut buffer = Vec::new();
f.read_to_end(&mut buffer);
lua_ctx.load(&*buffer).exec().is_err();

but I can't get it to work. Do you have any idea how to execute pre-compiled bytecode from a file?

@kyren
Copy link
Contributor

kyren commented Aug 16, 2019

The reason for that is that it's potential UB and needs a separate unsafe interface, which I've yet to add.

@elice02
Copy link
Author

elice02 commented Aug 17, 2019

I'm not sure why executing bytecode is considered so insecure? It's part of Lua and is no more or less secure than running arbitrary Lua scripts. Running scripts or bytecode from any insecure resource is a security risk, whether compiled or not. Obviously, scripts allow you to read the content, but that's not really relevant for me. Having precompiled content significantly speeds up what I'm trying to do.

@kyren
Copy link
Contributor

kyren commented Aug 17, 2019

It's not that it's insecure, it's that it's actually UB if the bytecode is malformed. As I understand it, there's no bounds checking on the indexes in the bytecode, so if the bytecode is corrupted or something it will just exhibit UB.

I'm not saying you shouldn't have the ability to do this, I'm just saying it needs a separate unsafe function to do it.

If you really need to do this right now you can do it by going through lua's loadfile function instead, which I realize is not super ergonomic.

This is sort of related to #116, I just haven't had time lately to actually sit down and solve all of this.

@elice02
Copy link
Author

elice02 commented Aug 17, 2019

ah ok, I get it. Thanks for the response. I think I will load the file from the file system for now using loadfile. :-)

Many thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants