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