OP_LOADKX not supported #43

Closed
opened 2019-06-30 17:35:39 +00:00 by Enyby · 0 comments
Enyby commented 2019-06-30 17:35:39 +00:00 (Migrated from github.com)

OP_LOADKX only declared in code. No any real support for it.
VM can not Handle this op code, compiler not produce it and so on.

Because of that you can get crash if you code need more than 2^18 (262144) unique constants. Something like that:

org.luaj.vm2.LuaError: compiler assert failed
        at org.luaj.vm2.compiler.Constants._assert(Constants.java:64)
        at org.luaj.vm2.compiler.FuncState.codeABx(FuncState.java:1116)
        at org.luaj.vm2.compiler.FuncState.discharge2reg(FuncState.java:588)
        at org.luaj.vm2.compiler.FuncState.exp2reg(FuncState.java:618)
        at org.luaj.vm2.compiler.FuncState.exp2nextreg(FuncState.java:645)
        at org.luaj.vm2.compiler.FuncState.closelistfield(FuncState.java:247)
        at org.luaj.vm2.compiler.LexState.constructor(LexState.java:1214)
        at org.luaj.vm2.compiler.LexState.simpleexp(LexState.java:1472)
        at org.luaj.vm2.compiler.LexState.subexpr(LexState.java:1577)
        at org.luaj.vm2.compiler.LexState.expr(LexState.java:1595)
        at org.luaj.vm2.compiler.LexState.explist(LexState.java:1312)
        at org.luaj.vm2.compiler.LexState.retstat(LexState.java:2028)
        at org.luaj.vm2.compiler.LexState.statement(LexState.java:2100)
        at org.luaj.vm2.compiler.LexState.statlist(LexState.java:2123)
        at org.luaj.vm2.compiler.LexState.mainfunc(LexState.java:2142)
        at org.luaj.vm2.compiler.LuaC$CompileState.luaY_parser(LuaC.java:129)
        at org.luaj.vm2.compiler.LuaC$CompileState.access$0(LuaC.java:120)
        at org.luaj.vm2.compiler.LuaC.compile(LuaC.java:99)
        at org.luaj.vm2.Globals.compilePrototype(Globals.java:304)
        at org.luaj.vm2.Globals.loadPrototype(Globals.java:283)
        at org.luaj.vm2.Globals.load(Globals.java:254)

Code for reproduce issue:

local a = {"return {0"}
for i = 1, 2^18 + 10 do
   a[#a + 1] = i
end
a[#a + 1] = "}"
f = io.open('test.lua', 'w')
f:write(table.concat(a, ","))
f:close()

It is generate huge test.lua. Run it. It must be ok, but produce compiler exception.

For most cases you not need such huge list of constants (more than 262144). So this issue maybe not happens for you at all.

OP_LOADKX only declared in code. No any real support for it. VM can not Handle this op code, compiler not produce it and so on. Because of that you can get crash if you code need more than 2^18 (262144) unique constants. Something like that: ``` org.luaj.vm2.LuaError: compiler assert failed at org.luaj.vm2.compiler.Constants._assert(Constants.java:64) at org.luaj.vm2.compiler.FuncState.codeABx(FuncState.java:1116) at org.luaj.vm2.compiler.FuncState.discharge2reg(FuncState.java:588) at org.luaj.vm2.compiler.FuncState.exp2reg(FuncState.java:618) at org.luaj.vm2.compiler.FuncState.exp2nextreg(FuncState.java:645) at org.luaj.vm2.compiler.FuncState.closelistfield(FuncState.java:247) at org.luaj.vm2.compiler.LexState.constructor(LexState.java:1214) at org.luaj.vm2.compiler.LexState.simpleexp(LexState.java:1472) at org.luaj.vm2.compiler.LexState.subexpr(LexState.java:1577) at org.luaj.vm2.compiler.LexState.expr(LexState.java:1595) at org.luaj.vm2.compiler.LexState.explist(LexState.java:1312) at org.luaj.vm2.compiler.LexState.retstat(LexState.java:2028) at org.luaj.vm2.compiler.LexState.statement(LexState.java:2100) at org.luaj.vm2.compiler.LexState.statlist(LexState.java:2123) at org.luaj.vm2.compiler.LexState.mainfunc(LexState.java:2142) at org.luaj.vm2.compiler.LuaC$CompileState.luaY_parser(LuaC.java:129) at org.luaj.vm2.compiler.LuaC$CompileState.access$0(LuaC.java:120) at org.luaj.vm2.compiler.LuaC.compile(LuaC.java:99) at org.luaj.vm2.Globals.compilePrototype(Globals.java:304) at org.luaj.vm2.Globals.loadPrototype(Globals.java:283) at org.luaj.vm2.Globals.load(Globals.java:254) ``` Code for reproduce issue: ``` local a = {"return {0"} for i = 1, 2^18 + 10 do a[#a + 1] = i end a[#a + 1] = "}" f = io.open('test.lua', 'w') f:write(table.concat(a, ",")) f:close() ``` It is generate huge test.lua. Run it. It must be ok, but produce compiler exception. For most cases you not need such huge list of constants (more than 262144). So this issue maybe not happens for you at all.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: open-autonomous-connection/luaj#43