Bugs

Here is a list of all bugs found in each release of Lua since 4.0. Each entry includes a minimal example that exhibits the bug and a patch or solution, when available.

Every Lua release fixes all listed bugs in previous releases, except where noted. Nevertheless, some bugs found in recent releases actually exist since older releases.

If you want to report a bug, please read this first.

'LUA_USE_READLINE' defined twice in FreeBSD recipe.

reported by Russell Haley on 13 Jul 2018. Patch: src/Makefile: @@ -104,2 +104,2 @@ freebsd: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -DLUA_USE_READLINE -I/usr/include/edit" SYSLIBS="-Wl,-E -ledit" CC="cc" + $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -I/usr/include/edit" SYSLIBS="-Wl,-E -ledit" CC="cc"

Wrong code generated for a 'goto' followed by a label inside an 'if'.

reported by 云风 on 13 Apr 2017. existed since 5.2. Example: -- should print 32323232..., but prints only '3' if true then goto LBL ::loop:: print(2) ::LBL:: print(3) goto loop end Patch: lparser.c: @@ -1392,7 +1392,7 @@ luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */ enterblock(fs, &bl, 0); /* must enter block before 'goto' */ gotostat(ls, v.t); /* handle goto/break */ - skipnoopstat(ls); /* skip other no-op statements */ + while (testnext(ls, ';')) {} /* skip semicolons */ if (block_follow(ls, 0)) { /* 'goto' is the entire block? */ leaveblock(fs); return; /* and that is it */ Lua crashes when building sequences with more than 2^30 elements.

reported by Viacheslav Usov on 11 May 2017. Example: -- crashes if machine has enough memory local t = {} for i = 1, 0x7fffffff do t[i] = i end Patch: ltable.c: @@ -223,7 +223,9 @@ unsigned int na = 0; /* number of elements to go to array part */ unsigned int optimal = 0; /* optimal size for array part */ /* loop while keys can fill more than half of total size */ - for (i = 0, twotoi = 1; *pna > twotoi / 2; i++, twotoi *= 2) { + for (i = 0, twotoi = 1; + twotoi > 0 && *pna > twotoi / 2; + i++, twotoi *= 2) { if (nums[i] > 0) { a += nums[i]; if (a > twotoi/2) { /* more than half elements present? */ Table length computation overflows for sequences larger than 2^31 elements.

reported by Viacheslav Usov on 12 May 2017. Example: -- on a machine with enough memory local t = {} for i = 1, 2147483681 do t[i] = i end print(#t) Patch: ltable.h: @@ -56,3 +56,3 @@ LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); -LUAI_FUNC int luaH_getn (Table *t); +LUAI_FUNC lua_Unsigned luaH_getn (Table *t); ltable.c: @@ -614,4 +614,4 @@ -static int unbound_search (Table *t, unsigned int j) { - unsigned int i = j; /* i is zero or a present index */ +static lua_Unsigned unbound_search (Table *t, lua_Unsigned j) { + lua_Unsigned i = j; /* i is zero or a present index */ j++; @@ -620,3 +620,3 @@ i = j; - if (j > cast(unsigned int, MAX_INT)/2) { /* overflow? */ + if (j > l_castS2U(LUA_MAXINTEGER) / 2) { /* overflow? */ /* table was built with bad purposes: resort to linear search */ @@ -630,3 +