mirror of
https://github.com/lua/lua
synced 2024-11-24 21:59:41 +03:00
Length of external strings must fit in Lua integer
(As the length of any string in Lua.)
This commit is contained in:
parent
0f7025dcae
commit
c1dc08e8e8
1
lapi.c
1
lapi.c
@ -551,6 +551,7 @@ LUA_API const char *lua_pushextlstring (lua_State *L,
|
|||||||
const char *s, size_t len, lua_Alloc falloc, void *ud) {
|
const char *s, size_t len, lua_Alloc falloc, void *ud) {
|
||||||
TString *ts;
|
TString *ts;
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
|
api_check(L, len <= MAX_SIZE, "string too large");
|
||||||
api_check(L, s[len] == '\0', "string not ending with zero");
|
api_check(L, s[len] == '\0', "string not ending with zero");
|
||||||
ts = luaS_newextlstr (L, s, len, falloc, ud);
|
ts = luaS_newextlstr (L, s, len, falloc, ud);
|
||||||
setsvalue2s(L, L->top.p, ts);
|
setsvalue2s(L, L->top.p, ts);
|
||||||
|
@ -538,10 +538,12 @@ static void newbox (lua_State *L) {
|
|||||||
*/
|
*/
|
||||||
static size_t newbuffsize (luaL_Buffer *B, size_t sz) {
|
static size_t newbuffsize (luaL_Buffer *B, size_t sz) {
|
||||||
size_t newsize = (B->size / 2) * 3; /* buffer size * 1.5 */
|
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)? */
|
if (l_unlikely(sz > MAX_SIZE - B->n - 1))
|
||||||
return luaL_error(B->L, "buffer too large");
|
return luaL_error(B->L, "resulting string too large");
|
||||||
if (newsize < B->n + sz + 1) /* not big enough? */
|
if (newsize < B->n + sz + 1 || newsize > MAX_SIZE) {
|
||||||
|
/* newsize was not big enough or too big */
|
||||||
newsize = B->n + sz + 1;
|
newsize = B->n + sz + 1;
|
||||||
|
}
|
||||||
return newsize;
|
return newsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ static size_t loadVarint (LoadState *S, size_t limit) {
|
|||||||
|
|
||||||
|
|
||||||
static size_t loadSize (LoadState *S) {
|
static size_t loadSize (LoadState *S) {
|
||||||
return loadVarint(S, MAX_SIZET);
|
return loadVarint(S, MAX_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3942,6 +3942,8 @@ holding the string content,
|
|||||||
and @id{len} is the length of the string.
|
and @id{len} is the length of the string.
|
||||||
The string should have a zero at its end,
|
The string should have a zero at its end,
|
||||||
that is, the condition @T{s[len] == '\0'} should hold.
|
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},
|
If @id{falloc} is different from @id{NULL},
|
||||||
that function will be called by Lua
|
that function will be called by Lua
|
||||||
|
Loading…
Reference in New Issue
Block a user