From 62d88295294755794bc87884baa3543bef63d29077ca0f7305f98f32e86468ee Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Sun, 18 Dec 2022 17:56:24 +0000 Subject: [PATCH] Accepting request 1043639 from home:gmbr3:Lua - Added more numbered patches from upstream: * luabugs8.patch * luabugs9.patch OBS-URL: https://build.opensuse.org/request/show/1043639 OBS-URL: https://build.opensuse.org/package/show/devel:languages:lua/lua54?expand=0&rev=63 --- lua54.changes | 7 +++ lua54.spec | 2 + luabugs8.patch | 148 +++++++++++++++++++++++++++++++++++++++++++++++++ luabugs9.patch | 102 ++++++++++++++++++++++++++++++++++ 4 files changed, 259 insertions(+) create mode 100644 luabugs8.patch create mode 100644 luabugs9.patch diff --git a/lua54.changes b/lua54.changes index 0d4767c..cf07719 100644 --- a/lua54.changes +++ b/lua54.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Sun Dec 18 17:55:21 UTC 2022 - Callum Farmer + +- Added more numbered patches from upstream: + * luabugs8.patch + * luabugs9.patch + ------------------------------------------------------------------- Tue Aug 30 16:40:09 UTC 2022 - Callum Farmer diff --git a/lua54.spec b/lua54.spec index 786ef6f..5284b82 100644 --- a/lua54.spec +++ b/lua54.spec @@ -51,6 +51,8 @@ Patch10: luabugs4.patch Patch11: luabugs5.patch Patch12: luabugs6.patch Patch13: luabugs7.patch +Patch14: luabugs8.patch +Patch15: luabugs9.patch # %if "%{flavor}" == "test" BuildRequires: lua54 diff --git a/luabugs8.patch b/luabugs8.patch new file mode 100644 index 0000000..f7dfbc9 --- /dev/null +++ b/luabugs8.patch @@ -0,0 +1,148 @@ +From a1089b415a3f5c753aa1b40758ffdaf28d5701b0 Mon Sep 17 00:00:00 2001 +From: Roberto Ierusalimschy +Date: Fri, 23 Sep 2022 10:41:16 -0300 +Subject: [PATCH] Bug: 'utf8.codes' accepts spurious continuation bytes + +--- + lutf8lib.c | 27 ++++++++++++++++----------- + testes/utf8.lua | 12 +++++++++++- + 2 files changed, 27 insertions(+), 12 deletions(-) + +diff --git a/lutf8lib.c b/lutf8lib.c +index e7bf098f6..3a5b9bc38 100644 +--- a/src/lutf8lib.c ++++ b/src/lutf8lib.c +@@ -25,6 +25,9 @@ + + #define MAXUTF 0x7FFFFFFFu + ++ ++#define MSGInvalid "invalid UTF-8 code" ++ + /* + ** Integer type for decoded UTF-8 values; MAXUTF needs 31 bits. + */ +@@ -35,7 +38,8 @@ typedef unsigned long utfint; + #endif + + +-#define iscont(p) ((*(p) & 0xC0) == 0x80) ++#define iscont(c) (((c) & 0xC0) == 0x80) ++#define iscontp(p) iscont(*(p)) + + + /* from strlib */ +@@ -65,7 +69,7 @@ static const char *utf8_decode (const char *s, utfint *val, int strict) { + int count = 0; /* to count number of continuation bytes */ + for (; c & 0x40; c <<= 1) { /* while it needs continuation bytes... */ + unsigned int cc = (unsigned char)s[++count]; /* read next byte */ +- if ((cc & 0xC0) != 0x80) /* not a continuation byte? */ ++ if (!iscont(cc)) /* not a continuation byte? */ + return NULL; /* invalid byte sequence */ + res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */ + } +@@ -140,7 +144,7 @@ static int codepoint (lua_State *L) { + utfint code; + s = utf8_decode(s, &code, !lax); + if (s == NULL) +- return luaL_error(L, "invalid UTF-8 code"); ++ return luaL_error(L, MSGInvalid); + lua_pushinteger(L, code); + n++; + } +@@ -190,16 +194,16 @@ static int byteoffset (lua_State *L) { + "position out of bounds"); + if (n == 0) { + /* find beginning of current byte sequence */ +- while (posi > 0 && iscont(s + posi)) posi--; ++ while (posi > 0 && iscontp(s + posi)) posi--; + } + else { +- if (iscont(s + posi)) ++ if (iscontp(s + posi)) + return luaL_error(L, "initial position is a continuation byte"); + if (n < 0) { + while (n < 0 && posi > 0) { /* move back */ + do { /* find beginning of previous character */ + posi--; +- } while (posi > 0 && iscont(s + posi)); ++ } while (posi > 0 && iscontp(s + posi)); + n++; + } + } +@@ -208,7 +212,7 @@ static int byteoffset (lua_State *L) { + while (n > 0 && posi < (lua_Integer)len) { + do { /* find beginning of next character */ + posi++; +- } while (iscont(s + posi)); /* (cannot pass final '\0') */ ++ } while (iscontp(s + posi)); /* (cannot pass final '\0') */ + n--; + } + } +@@ -226,15 +230,15 @@ static int iter_aux (lua_State *L, int strict) { + const char *s = luaL_checklstring(L, 1, &len); + lua_Unsigned n = (lua_Unsigned)lua_tointeger(L, 2); + if (n < len) { +- while (iscont(s + n)) n++; /* skip continuation bytes */ ++ while (iscontp(s + n)) n++; /* go to next character */ + } + if (n >= len) /* (also handles original 'n' being negative) */ + return 0; /* no more codepoints */ + else { + utfint code; + const char *next = utf8_decode(s + n, &code, strict); +- if (next == NULL) +- return luaL_error(L, "invalid UTF-8 code"); ++ if (next == NULL || iscontp(next)) ++ return luaL_error(L, MSGInvalid); + lua_pushinteger(L, n + 1); + lua_pushinteger(L, code); + return 2; +@@ -253,7 +257,8 @@ static int iter_auxlax (lua_State *L) { + + static int iter_codes (lua_State *L) { + int lax = lua_toboolean(L, 2); +- luaL_checkstring(L, 1); ++ const char *s = luaL_checkstring(L, 1); ++ luaL_argcheck(L, !iscontp(s), 1, MSGInvalid); + lua_pushcfunction(L, lax ? iter_auxlax : iter_auxstrict); + lua_pushvalue(L, 1); + lua_pushinteger(L, 0); +diff --git a/testes/utf8.lua b/testes/utf8.lua +index 461e223c7..7472cfd05 100644 +--- a/testes/utf8.lua ++++ b/testes/utf8.lua +@@ -97,9 +97,15 @@ do -- error indication in utf8.len + assert(not a and b == p) + end + check("abc\xE3def", 4) +- check("汉字\x80", #("汉字") + 1) + check("\xF4\x9F\xBF", 1) + check("\xF4\x9F\xBF\xBF", 1) ++ -- spurious continuation bytes ++ check("汉字\x80", #("汉字") + 1) ++ check("\x80hello", 1) ++ check("hel\x80lo", 4) ++ check("汉字\xBF", #("汉字") + 1) ++ check("\xBFhello", 1) ++ check("hel\xBFlo", 4) + end + + -- errors in utf8.codes +@@ -112,12 +118,16 @@ do + end + errorcodes("ab\xff") + errorcodes("\u{110000}") ++ errorcodes("in\x80valid") ++ errorcodes("\xbfinvalid") ++ errorcodes("αλφ\xBFα") + + -- calling interation function with invalid arguments + local f = utf8.codes("") + assert(f("", 2) == nil) + assert(f("", -1) == nil) + assert(f("", math.mininteger) == nil) ++ + end + + -- error in initial position for offset diff --git a/luabugs9.patch b/luabugs9.patch new file mode 100644 index 0000000..c92cf1f --- /dev/null +++ b/luabugs9.patch @@ -0,0 +1,102 @@ +From 1e64c1391f9a14115b5cc82066dbf545ae73ee27 Mon Sep 17 00:00:00 2001 +From: Roberto Ierusalimschy +Date: Tue, 25 Oct 2022 16:44:06 -0300 +Subject: [PATCH] Bug: stack overflow with nesting of coroutine.close + +--- + lcorolib.c | 4 ++-- + lstate.c | 3 ++- + ltests.c | 2 +- + lua.h | 2 +- + manual/manual.of | 7 ++++++- + testes/cstack.lua | 26 ++++++++++++++++++++++++++ + 6 files changed, 38 insertions(+), 6 deletions(-) + +diff --git a/lcorolib.c b/lcorolib.c +index 785a1e81a..40b880b14 100644 +--- a/src/lcorolib.c ++++ b/src/lcorolib.c +@@ -76,7 +76,7 @@ static int luaB_auxwrap (lua_State *L) { + if (l_unlikely(r < 0)) { /* error? */ + int stat = lua_status(co); + if (stat != LUA_OK && stat != LUA_YIELD) { /* error in the coroutine? */ +- stat = lua_resetthread(co); /* close its tbc variables */ ++ stat = lua_resetthread(co, L); /* close its tbc variables */ + lua_assert(stat != LUA_OK); + lua_xmove(co, L, 1); /* move error message to the caller */ + } +@@ -172,7 +172,7 @@ static int luaB_close (lua_State *L) { + int status = auxstatus(L, co); + switch (status) { + case COS_DEAD: case COS_YIELD: { +- status = lua_resetthread(co); ++ status = lua_resetthread(co, L); + if (status == LUA_OK) { + lua_pushboolean(L, 1); + return 1; +diff --git a/lstate.c b/lstate.c +index 1ffe1a0f7..4b5c10008 100644 +--- a/src/lstate.c ++++ b/src/lstate.c +@@ -343,9 +343,10 @@ int luaE_resetthread (lua_State *L, int status) { + } + + +-LUA_API int lua_resetthread (lua_State *L) { ++LUA_API int lua_resetthread (lua_State *L, lua_State *from) { + int status; + lua_lock(L); ++ L->nCcalls = (from) ? getCcalls(from) : 0; + status = luaE_resetthread(L, L->status); + lua_unlock(L); + return status; +diff --git a/lua.h b/lua.h +index 219784cc0..bfba4d1e1 100644 +--- a/src/lua.h ++++ b/src/lua.h +@@ -153,7 +153,7 @@ extern const char lua_ident[]; + LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); + LUA_API void (lua_close) (lua_State *L); + LUA_API lua_State *(lua_newthread) (lua_State *L); +-LUA_API int (lua_resetthread) (lua_State *L); ++LUA_API int (lua_resetthread) (lua_State *L, lua_State *from); + + LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); + +diff --git a/testes/cstack.lua b/testes/cstack.lua +index ca76c8729..97afe9fd0 100644 +--- a/testes/cstack.lua ++++ b/testes/cstack.lua +@@ -84,6 +84,32 @@ do -- bug in 5.4.0 + end + + ++do -- bug since 5.4.0 ++ local count = 0 ++ print("chain of 'coroutine.close'") ++ -- create N coroutines forming a list so that each one, when closed, ++ -- closes the previous one. (With a large enough N, previous Lua ++ -- versions crash in this test.) ++ local coro = false ++ for i = 1, 1000 do ++ local previous = coro ++ coro = coroutine.create(function() ++ local cc = setmetatable({}, {__close=function() ++ count = count + 1 ++ if previous then ++ assert(coroutine.close(previous)) ++ end ++ end}) ++ coroutine.yield() -- leaves 'cc' pending to be closed ++ end) ++ assert(coroutine.resume(coro)) -- start it and run until it yields ++ end ++ local st, msg = coroutine.close(coro) ++ assert(not st and string.find(msg, "C stack overflow")) ++ print("final count: ", count) ++end ++ ++ + do + print("nesting of resuming yielded coroutines") + local count = 0