0012-fix-reader-at-eoz.patch 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. When loading a file, Lua may call the reader function again after it returned end of input.
  2. Fetch from: http://www.lua.org/bugs.html#5.1.5-2
  3. Signed-off-by: Francois Perrad <francois.perrad@gadz.org>
  4. Index: b/src/lzio.c
  5. ===================================================================
  6. --- a/src/lzio.c
  7. +++ b/src/lzio.c
  8. @@ -22,10 +22,14 @@
  9. size_t size;
  10. lua_State *L = z->L;
  11. const char *buff;
  12. + if (z->eoz) return EOZ;
  13. lua_unlock(L);
  14. buff = z->reader(L, z->data, &size);
  15. lua_lock(L);
  16. - if (buff == NULL || size == 0) return EOZ;
  17. + if (buff == NULL || size == 0) {
  18. + z->eoz = 1; /* avoid calling reader function next time */
  19. + return EOZ;
  20. + }
  21. z->n = size - 1;
  22. z->p = buff;
  23. return char2int(*(z->p++));
  24. @@ -51,6 +55,7 @@
  25. z->data = data;
  26. z->n = 0;
  27. z->p = NULL;
  28. + z->eoz = 0;
  29. }
  30. Index: b/src/lzio.h
  31. ===================================================================
  32. --- a/src/lzio.h
  33. +++ b/src/lzio.h
  34. @@ -59,6 +59,7 @@
  35. lua_Reader reader;
  36. void* data; /* additional data */
  37. lua_State *L; /* Lua state (for reader) */
  38. + int eoz; /* true if reader has no more data */
  39. };