Change in dumping of NULL strings
When dumping a string, adding 2 to its size may overflow a size_t for external strings, which may not have a header. (Adding 1 is Ok, because all strings end with a '\0' not included in their size.) The new method for saving NULL strings code them as a repeated string, using the reserved index 0.
This commit is contained in:
12
lundump.c
12
lundump.c
@@ -147,20 +147,20 @@ static void loadString (LoadState *S, Proto *p, TString **sl) {
|
||||
TString *ts;
|
||||
TValue sv;
|
||||
size_t size = loadSize(S);
|
||||
if (size == 0) { /* no string? */
|
||||
lua_assert(*sl == NULL); /* must be prefilled */
|
||||
return;
|
||||
}
|
||||
else if (size == 1) { /* previously saved string? */
|
||||
if (size == 0) { /* previously saved string? */
|
||||
lua_Unsigned idx = loadVarint(S, LUA_MAXUNSIGNED); /* get its index */
|
||||
TValue stv;
|
||||
if (idx == 0) { /* no string? */
|
||||
lua_assert(*sl == NULL); /* must be prefilled */
|
||||
return;
|
||||
}
|
||||
if (novariant(luaH_getint(S->h, l_castU2S(idx), &stv)) != LUA_TSTRING)
|
||||
error(S, "invalid string index");
|
||||
*sl = ts = tsvalue(&stv); /* get its value */
|
||||
luaC_objbarrier(L, p, ts);
|
||||
return; /* do not save it again */
|
||||
}
|
||||
else if ((size -= 2) <= LUAI_MAXSHORTLEN) { /* short string? */
|
||||
else if ((size -= 1) <= LUAI_MAXSHORTLEN) { /* short string? */
|
||||
char buff[LUAI_MAXSHORTLEN + 1]; /* extra space for '\0' */
|
||||
loadVector(S, buff, size + 1); /* load string into buffer */
|
||||
*sl = ts = luaS_newlstr(L, buff, size); /* create string */
|
||||
|
||||
Reference in New Issue
Block a user