From 03718bdb76a3d9dd9a28caf862d590e78a6739aa Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Fri, 9 Nov 2018 11:49:22 -0500 Subject: Lua fix reader bug in lzio When loading a file, Lua may call the reader function again after it returned end of input https://www.lua.org/bugs.html#5.1.5-2 Change-Id: Ic2f4d727705a0b8f48ce792f6a9f7af25a503037 --- apps/plugins/lua/lzio.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/plugins/lua/lzio.c b/apps/plugins/lua/lzio.c index 293edd59b0..54d5ec4741 100644 --- a/apps/plugins/lua/lzio.c +++ b/apps/plugins/lua/lzio.c @@ -22,10 +22,15 @@ int luaZ_fill (ZIO *z) { size_t size; lua_State *L = z->L; const char *buff; + if (!z->reader) + return EOZ; lua_unlock(L); buff = z->reader(L, z->data, &size); lua_lock(L); - if (buff == NULL || size == 0) return EOZ; + if (buff == NULL || size == 0) { + z->reader = NULL; /* avoid calling reader function next time */ + return EOZ; + } z->n = size - 1; z->p = buff; return char2int(*(z->p++)); -- cgit v1.2.3