Length of external strings must fit in Lua integer · lua/lua@c1dc08e · GitHub
Skip to content

Commit c1dc08e

Browse files
committed
Length of external strings must fit in Lua integer
(As the length of any string in Lua.)
1 parent 0f7025d commit c1dc08e

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎lapi.c‎

Lines changed: 1 addition & 0 deletions

‎lauxlib.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,12 @@ static void newbox (lua_State *L) {
538538
*/
539539
static size_t newbuffsize (luaL_Buffer *B, size_t sz) {
540540
size_t newsize = (B->size / 2) * 3; /* buffer size * 1.5 */
541-
if (l_unlikely(MAX_SIZET - sz - 1 < B->n)) /* overflow in (B->n + sz + 1)? */
542-
return luaL_error(B->L, "buffer too large");
543-
if (newsize < B->n + sz + 1) /* not big enough? */
541+
if (l_unlikely(sz > MAX_SIZE - B->n - 1))
542+
return luaL_error(B->L, "resulting string too large");
543+
if (newsize < B->n + sz + 1 || newsize > MAX_SIZE) {
544+
/* newsize was not big enough or too big */
544545
newsize = B->n + sz + 1;
546+
}
545547
return newsize;
546548
}
547549

‎lundump.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static size_t loadVarint (LoadState *S, size_t limit) {
109109

110110

111111
static size_t loadSize (LoadState *S) {
112-
return loadVarint(S, MAX_SIZET);
112+
return loadVarint(S, MAX_SIZE);
113113
}
114114

115115

‎manual/manual.of‎

Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)