aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lundump.js14
-rw-r--r--test/load.test.js18
2 files changed, 23 insertions, 9 deletions
diff --git a/src/lundump.js b/src/lundump.js
index cf3fafa..2213015 100644
--- a/src/lundump.js
+++ b/src/lundump.js
@@ -108,16 +108,12 @@ class BytecodeParser {
}
readString() {
- let size = Math.max(this.readByte() - 1, 0);
-
- if (size + 1 === 0xFF)
- size = this.readSize_t() - 1;
-
- if (size === 0) {
+ let size = this.readByte();
+ if (size === 0xFF)
+ size = this.readSize_t();
+ if (size === 0)
return null;
- }
-
- return luaS_bless(this.L, this.read(size));
+ return luaS_bless(this.L, this.read(size-1));
}
/* creates a mask with 'n' 1 bits at position 'p' */
diff --git a/test/load.test.js b/test/load.test.js
index 3c03eec..d778155 100644
--- a/test/load.test.js
+++ b/test/load.test.js
@@ -43,6 +43,24 @@ test('load', () => {
});
+test('undump empty string', () => {
+ let L = lauxlib.luaL_newstate();
+ if (!L) throw Error("failed to create lua state");
+
+ let luaCode = `
+ assert(load(string.dump(function()
+ local str = ""
+ return #str -- something that inspects the string
+ end)))()
+ `;
+ {
+ lualib.luaL_openlibs(L);
+ expect(lauxlib.luaL_loadstring(L, to_luastring(luaCode))).toBe(lua.LUA_OK);
+ lua.lua_call(L, 0, 0);
+ }
+});
+
+
test('luaL_loadbuffer', () => {
let L = lauxlib.luaL_newstate();
if (!L) throw Error("failed to create lua state");