Skip to content
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

Add/Fix pre-compiled Bytecode support #1604

Closed
Duck375 opened this issue Oct 6, 2023 · 3 comments
Closed

Add/Fix pre-compiled Bytecode support #1604

Duck375 opened this issue Oct 6, 2023 · 3 comments
Labels
area-Core This affects CC's core (the Lua runtime, APIs, computer internals). bug A problem or unexpected behaviour with the mod. cannot reproduce I'm unable to reproduce this bug.

Comments

@Duck375
Copy link

Duck375 commented Oct 6, 2023

Why?

As decribed in http://lua-users.org/wiki/LuaCompilerInLua, lua should be able to replicate work of luac program (Luac is used to generate executable bytecode from raw lua file)
At current moment pure lua implementation of Luac CAN produce executable files, but it's execution is limited up to 1 function, after which it throws error
file.lua:2 vm error: java.lang.ArrayIndexOutOfBoundsException: Index 253 out of bounds for length 2
Using pre-compiled bytecode has it's upsides and downsides.
Example: securing original lua source code on computer, by using pre-compiled file with stripped debug information, with neat addition of faster loading, but need to recompile every time source code is changed, since direct editing bytecode is usually a bad idea.

@SquidDev SquidDev added bug A problem or unexpected behaviour with the mod. area-Core This affects CC's core (the Lua runtime, APIs, computer internals). labels Oct 6, 2023
@SquidDev
Copy link
Member

SquidDev commented Oct 6, 2023

Can you provide some complete reproduction steps here (input file, etc...) and your logs. I cannot reproduce this in my testing - the loaded functions behave as expected.

Note that bytecode files cannot be executed from the shell or with loadfile directly, as files are not loaded with binary mode #1246. Also be aware that the bytecode format is unstable, and may change between versions. I would strongly recommend not going anywhere near it.

@SquidDev SquidDev added the cannot reproduce I'm unable to reproduce this bug. label Oct 6, 2023
@Duck375
Copy link
Author

Duck375 commented Oct 6, 2023

Using:
Minecraft - 1.19.2
Computer Craft: Tweaked - version 1.101.3

  1. copy code from page (the last code block with support of arguments) and save it
  2. write any program (in my case it was 3 simple prints)
  3. compile it using luac
  4. run it in different ways (tried direct run and loadfile() at first, dofile(), require())
    image

@SquidDev
Copy link
Member

SquidDev commented Oct 6, 2023

Ahhh, you are using loadfile (or its derivatives). That doesn't work, as files are not loaded in binary mode - see #1246. You could write a wrapper program which contains the actual payload as a (correctly encoded) string, but honestly your best bet is just, well, don't pre-compile files :p.

I've opened an issue on our Lua VM repo to see if we can do any verification of the generated bytecode, and thus catch these issues earlier.

@SquidDev SquidDev closed this as not planned Won't fix, can't repro, duplicate, stale Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Core This affects CC's core (the Lua runtime, APIs, computer internals). bug A problem or unexpected behaviour with the mod. cannot reproduce I'm unable to reproduce this bug.
Projects
None yet
Development

No branches or pull requests

2 participants