Length of external strings must fit in Lua integer

(As the length of any string in Lua.)
diff --git a/lapi.c b/lapi.c
index 2b14c15..f00bd53 100644
--- a/lapi.c
+++ b/lapi.c
@@ -551,6 +551,7 @@
 	        const char *s, size_t len, lua_Alloc falloc, void *ud) {
   TString *ts;
   lua_lock(L);
+  api_check(L, len <= MAX_SIZE, "string too large");
   api_check(L, s[len] == '\0', "string not ending with zero");
   ts = luaS_newextlstr (L, s, len, falloc, ud);
   setsvalue2s(L, L->top.p, ts);
diff --git a/lauxlib.c b/lauxlib.c
index 99a6309..5aeec55 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -538,10 +538,12 @@
 */
 static size_t newbuffsize (luaL_Buffer *B, size_t sz) {
   size_t newsize = (B->size / 2) * 3;  /* buffer size * 1.5 */
-  if (l_unlikely(MAX_SIZET - sz - 1 < B->n))  /* overflow in (B->n + sz + 1)? */
-    return luaL_error(B->L, "buffer too large");
-  if (newsize < B->n + sz + 1)  /* not big enough? */
+  if (l_unlikely(sz > MAX_SIZE - B->n - 1))
+    return luaL_error(B->L, "resulting string too large");
+  if (newsize < B->n + sz + 1 || newsize > MAX_SIZE) {
+    /* newsize was not big enough or too big */
     newsize = B->n + sz + 1;
+  }
   return newsize;
 }
 
diff --git a/lundump.c b/lundump.c
index 51d5dc6..b5dbaec 100644
--- a/lundump.c
+++ b/lundump.c
@@ -109,7 +109,7 @@
 
 
 static size_t loadSize (LoadState *S) {
-  return loadVarint(S, MAX_SIZET);
+  return loadVarint(S, MAX_SIZE);
 }
 
 
diff --git a/manual/manual.of b/manual/manual.of
index 774981c..56619af 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -3942,6 +3942,8 @@
 and @id{len} is the length of the string.
 The string should have a zero at its end,
 that is, the condition @T{s[len] == '\0'} should hold.
+As with any string in Lua,
+the length must fit in a Lua integer.
 
 If @id{falloc} is different from @id{NULL},
 that function will be called by Lua