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
This commit is contained in:
William Wilgus 2018-11-09 11:49:22 -05:00
parent b69faf0bcc
commit 03718bdb76

View file

@ -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++));