Text of lua.org › bugs.html as Styx crawled it on Nov 18, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Lua: bugs

Bugs 5.5 · 5.4 · 5.3 · 5.2 · 5.1 · 5.0 · 4.0 Here is a list of all bugs found in each release of Lua since 4.0. 5.5: 5.5.1 · 5.5.0 5.4: 5.4.9 · 5.4.8 · 5.4.7 · 5.4.6 · 5.4.5 · 5.4.4 · 5.4.3 · 5.4.2 · 5.4.1 · 5.4.0 5.3: 5.3.6 · 5.3.5 · 5.3.4 · 5.3.3 · 5.3.2 · 5.3.1 · 5.3.0 5.2: 5.2.4 · 5.2.3 · 5.2.2 · 5.2.1 · 5.2.0 5.1: 5.1.5 · 5.1.4 · 5.1.3 · 5.1.2 · 5.1.1 · 5.1 5.0: 5.0.3 · 5.0.2 · 5.0 4.0: 4.0 Each entry includes a minimal example that exhibits the bug and a patch or solution, when available.

Larger fixes appear in Lua's GitHub repository , which is mirrored irregularly. Every Lua release fixes all listed bugs in previous releases, except where noted. Some bugs found in newer releases may have existed in older releases. If you want to report a bug, please read this first. Lua 5.5.1 1 · 2 · 3 · 4 'luaO_applyparam' can be called with a negative parameter, causing a negative value to be left-shifted (undefined behavior). reported by Sergey Bronnikov on 26 Aug 2026. existed since 5.0. fixed in github .

Example: -- To be run with Lua compiled with -fsanitize=undefined local lim = 1e6 -- make major collections non-incremental collectgarbage("param", "stepmul", 0) -- make "majorminor" large enough to force a left-shift -- when applying the parameter (internal details) collectgarbage("param", "majorminor", 2000) collectgarbage(); collectgarbage() local M = collectgarbage"count" -- create a large table local t = {} for i = 1, lim do t[i] = true end assert(collectgarbage"count" > M + (lim * string.packsize"j")/1024) -- force collector to "generational major" mode collectgarbage"step" collectgarbage"step" collectgarbage"step" assert(not T or T.gcquery() == "genmajor") -- shrink the table for i = 1, lim do t[i] = nil end t[2 * lim] = true assert(collectgarbage"count" < M * 5/4) collectgarbage"step" -- assert violation Wrong semantics in numeric for loops with NaN arguments. reported by Yuexuan Zhang on 08 Oct 2026. existed since 5.3. fixed in github .

Example: -- The following loop should not run, as the initial value (1) is not -- larger than or equal to the limit 0/0 (NaN). for i = 1, 0/0, -1 do error("should not run the loop") end Wrong optimization changes result of (-0.0 - 0). reported by Yuexuan Zhang on 11 Oct 2026. existed since 5.4. fixed in github . Example: -- (-0.0 - 0) should result in -0.0 print(-0.0 - 0) --> 0.0 Calling coroutine.close while closing a coroutine after an error reports an error with no error message. reported by Xmilia Hermit on 12 Oct 2026. existed since 5.5.0. fixed in github .

Example: coroutine.wrap(function() local a <close> = setmetatable({}, {__close=function() coroutine.close(coroutine.running()) end}) error("y") end)() Lua 5.5.0 1 · 2 · 3 · 4 · 5 · 6 · 7 · 8 Arithmetic overflow in 'collectgarbage"step"'. reported by Sergey Bronnikov on 23 Dec 2025. existed since 5.0.0. fixed in 5.5.1. fixed in github . Example: -- Lua must be compiled with '-fsanitize=undefined' -- allocate some space to make gc debt negative (stack space does not -- invoke GC), and then call 'collectgarbage"step"' with a huge step. local function deep (n) if n == 0 then collectgarbage("step", math.maxinteger) else deep(n - 1) end end deep(26) Patch: lapi.c: @@ -1205,6 +1205,8 @@ LUA_API int lua_gc (lua_State *L, int what, ...) { g->gcstp = 0; /* allow GC to run (other bits must be zero here) */ if (n <= 0) n = g->GCdebt; /* force to run one basic step */ + else if (g->GCdebt < n - MAX_LMEM) /* overflow? */ + n = MAX_LMEM + g->GCdebt; /* trim 'n' (debt must be negative) */ luaE_setdebt(g, g->GCdebt - n); luaC_condGC(L, (void)0, work = 1); if (work && g->gcstate == GCSpause) /* end of cycle? */ 'string.packsize' can overflow result in 32-bit machines using 64-bit integers. reported by Matěj Cepl on 31 Dec 2025. existed since 5.5.0. fixed in 5.5.1. fixed in github .

Example: $ lua > print(string.packsize("T"), string.packsize("j")) 4 8 -- 32-bit size_t, 64-bit Lua integers > string.packsize("c4294967287c8") 4294967295 -- correct > string.packsize("c4294967287c9") 0 -- overflow Patch: lstrlib.c: @@ -1726,7 +1726,7 @@ static int str_packsize (lua_State *L) { luaL_argcheck(L, opt != Kstring && opt != Kzstr, 1, "variable-length format"); size += ntoalign; /* total space used by option */ - luaL_argcheck(L, totalsize <= LUA_MAXINTEGER - size, + luaL_argcheck(L, totalsize <= MAX_SIZE - size, 1, "format result too large"); totalsize += size; } Overflow in shift exponent when decoding invalid UTF-8 sequence. reported by Sergey Bronnikov on 16 Feb 2026. existed since 5.4.0. fixed in 5.5.1. fixed in github .

Example: -- Lua must be compiled with '-fsanitize=undefined' assert(not utf8.len("\xff\x8f\x8f\x8f\x8f\x8f\x8f\x8f")) Loading a binary chunk does not run the garbage collector. reported by Francisco Olarte on 18 Mar 2026. existed since 5.3. fixed in 5.5.1. fixed in github . Example: -- the following program needs lots of memory to run local s = "return 34" s = string.dump(load(s)) for i = 1, 1e8 do load(s) end io.write(collectgarbage"count" * 1024, "\n") Function returned by 'string.gmatch' can be left in an inconsistent state after an error. reported by Tao Sauvage on 30 Mar 2026. existed since 5.3. fixed in 5.5.1. fixed in github .

Example: local N = 200000 local iter = string.gmatch(string.rep("a", N), string.rep("a?", N)) pcall(iter) iter() 'lua_load' does not preserve the stack through the calls to the reader function. reported by Jure Bagić on 19 Apr 2026. existed since 5.5.0. fixed in 5.5.1. fixed in github . Example: See the new tests in the fix commit. The use of 'luaL_newmetatable' can leave an incomplete metatable in the registry. reported by Payo Nel on 06 Jun 2026. existed since 5.4. fixed in 5.5.1. fixed in github .

Example: Practically any use of luaL_newmetatable that uses its return value to conditionally initialize the metatable suffers from this problem, as a memory-allocation error while adding metamethods will leave an incomplete metatable in the registry, and subsequent calls to luaL_newmetatable will just reuse that incomplete metatable. A reproducible example is tricky, as it needs a memory-allocation failure in an exact point the first time the program creates the metatable.

Write barrier not properly executed in some updates through __newindex. reported by Sergey Bronnikov on 21 May 2026. existed since 5.4. fixed in 5.5.1. fixed in github . Example: local parent = {} parent.__newindex = parent collectgarbage() local child = setmetatable({}, parent) child.__newindex = {x = "hello"} collectgarbage("step") assert(parent.__newindex.x == "hello") Lua 5.4.9 That was the last release of Lua 5.4.

Bugs reported later are most likely fixed in Lua 5.5. Lua 5.4.8 1 · 2 · 3 · 4 New metatable in an all-weak table can fool the GC. reported by jy l on 12 Jun 2025. existed since 5.3.0 (at least). fixed in github . Example: -- (needs test library) collectgarbage"incremental" T.gcstate("propagate") local t = setmetatable({}, {__mode = "kv"}) T.gcstate("atomic") setmetatable(t, {__mode = "kv"}) T.gcstate("pause") print(getmetatable(t).__mode) Patch: lgc.c: @@ -553,8 +553,12 @@ static lu_mem traversetable (global_State *g, Table *h) { traverseweakvalue(g, h); else if (!weakvalue) /* strong values? */ traverseephemeron(g, h, 0); - else /* all weak */ - linkgclist(h, g->allweak); /* nothing to traverse now */ + else { /* all weak */ + if (g->gcstate == GCSpropagate) + linkgclist(h, g->grayagain); /* must visit again its metatable */ + else + linkgclist(h, g->allweak); /* must clear collected entries */ + } } else /* not weak */ traversestrongtable(g, h); Lua raises an error when given the option '--' without a script. reported by Jure Bagić on 04 Jul 2025. existed since 5.4.6. fixed in github .

Example: $ lua -i -- Lua 5.4.8 Copyright (C) 1994-2025 Lua.org, PUC-Rio lua: not enough memory Patch: lua.c: @@ -302,7 +302,8 @@ static int collectargs (char **argv, int *first) { case '-': /* '--' */ if (argv[i][2] !=

The rest of this page is on the live site.