8a89db
diff -up lua-5.4.2/src/ldebug.c.orig lua-5.4.2/src/ldebug.c
8a89db
--- lua-5.4.2/src/ldebug.c.orig	2020-11-13 16:32:00.000000000 +0100
8a89db
+++ lua-5.4.2/src/ldebug.c	2022-10-21 14:35:02.200941813 +0200
8a89db
@@ -772,8 +772,11 @@ l_noret luaG_runerror (lua_State *L, con
8a89db
   va_start(argp, fmt);
8a89db
   msg = luaO_pushvfstring(L, fmt, argp);  /* format message */
8a89db
   va_end(argp);
8a89db
-  if (isLua(ci))  /* if Lua function, add source:line information */
8a89db
+  if (isLua(ci)) {  /* if Lua function, add source:line information */
8a89db
     luaG_addinfo(L, msg, ci_func(ci)->p->source, getcurrentline(ci));
8a89db
+    setobjs2s(L, L->top - 2, L->top - 1);  /* remove 'msg' from the stack */
8a89db
+    L->top--;
8a89db
+  }
8a89db
   luaG_errormsg(L);
8a89db
 }
8a89db
 
8a89db
diff -up lua-5.4.2/src/lvm.c.orig lua-5.4.2/src/lvm.c
8a89db
--- lua-5.4.2/src/lvm.c.orig	2020-11-13 16:32:02.000000000 +0100
8a89db
+++ lua-5.4.2/src/lvm.c	2022-10-21 14:35:31.713755890 +0200
8a89db
@@ -641,7 +641,7 @@ void luaV_concat (lua_State *L, int tota
8a89db
     int n = 2;  /* number of elements handled in this pass (at least 2) */
8a89db
     if (!(ttisstring(s2v(top - 2)) || cvt2str(s2v(top - 2))) ||
8a89db
         !tostring(L, s2v(top - 1)))
8a89db
-      luaT_tryconcatTM(L);
8a89db
+      luaT_tryconcatTM(L);  /* may invalidate 'top' */
8a89db
     else if (isemptystr(s2v(top - 1)))  /* second operand is empty? */
8a89db
       cast_void(tostring(L, s2v(top - 2)));  /* result is first operand */
8a89db
     else if (isemptystr(s2v(top - 2))) {  /* first operand is empty string? */
8a89db
@@ -654,8 +654,10 @@ void luaV_concat (lua_State *L, int tota
8a89db
       /* collect total length and number of strings */
8a89db
       for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) {
8a89db
         size_t l = vslen(s2v(top - n - 1));
8a89db
-        if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl))
8a89db
+        if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) {
8a89db
+          L->top = top - total;  /* pop strings to avoid wasting stack */
8a89db
           luaG_runerror(L, "string length overflow");
8a89db
+        }
8a89db
         tl += l;
8a89db
       }
8a89db
       if (tl <= LUAI_MAXSHORTLEN) {  /* is result a short string? */
8a89db
@@ -669,8 +671,8 @@ void luaV_concat (lua_State *L, int tota
8a89db
       }
8a89db
       setsvalue2s(L, top - n, ts);  /* create result */
8a89db
     }
8a89db
-    total -= n-1;  /* got 'n' strings to create 1 new */
8a89db
-    L->top -= n-1;  /* popped 'n' strings and pushed one */
8a89db
+    total -= n - 1;  /* got 'n' strings to create one new */
8a89db
+    L->top -= n - 1;  /* popped 'n' strings and pushed one */
8a89db
   } while (total > 1);  /* repeat until only 1 result left */
8a89db
 }
8a89db