diff options
author | William Wilgus <me.theuser@yahoo.com> | 2018-11-09 11:49:22 -0500 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2018-11-15 11:20:54 +0100 |
commit | 03718bdb76a3d9dd9a28caf862d590e78a6739aa (patch) | |
tree | 6e712eccfe6876238f88d27eb56ae928f25fb59d | |
parent | b69faf0bcc5ddca1d88b1a7ab47bcbbc6dbb9af1 (diff) | |
download | rockbox-03718bdb76a3d9dd9a28caf862d590e78a6739aa.tar.gz rockbox-03718bdb76a3d9dd9a28caf862d590e78a6739aa.zip |
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
-rw-r--r-- | apps/plugins/lua/lzio.c | 7 |
1 files changed, 6 insertions, 1 deletions
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) { | |||
22 | size_t size; | 22 | size_t size; |
23 | lua_State *L = z->L; | 23 | lua_State *L = z->L; |
24 | const char *buff; | 24 | const char *buff; |
25 | if (!z->reader) | ||
26 | return EOZ; | ||
25 | lua_unlock(L); | 27 | lua_unlock(L); |
26 | buff = z->reader(L, z->data, &size); | 28 | buff = z->reader(L, z->data, &size); |
27 | lua_lock(L); | 29 | lua_lock(L); |
28 | if (buff == NULL || size == 0) return EOZ; | 30 | if (buff == NULL || size == 0) { |
31 | z->reader = NULL; /* avoid calling reader function next time */ | ||
32 | return EOZ; | ||
33 | } | ||
29 | z->n = size - 1; | 34 | z->n = size - 1; |
30 | z->p = buff; | 35 | z->p = buff; |
31 | return char2int(*(z->p++)); | 36 | return char2int(*(z->p++)); |