From e398e03aa90546925416f41508dba9709151a1c2 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 13 Jul 2020 15:38:55 -0300 Subject: [PATCH] Bug fix: emergency collection while loading upvalues In 'lundump.c', when loading the upvalues of a function, there can be a read error if the chunk is truncated. In that case, the creation of the error message can trigger an emergency collection while the prototype is still anchored. So, the prototype must be GC consistent before loading the upvales, which implies that it the 'name' fields must be filled with NULL before the reading. --- lundump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lundump.c b/lundump.c index 4243678a..8f2b4db0 100644 --- a/lundump.c +++ b/lundump.c @@ -205,8 +205,9 @@ static void loadUpvalues (LoadState *S, Proto *f) { n = loadInt(S); f->upvalues = luaM_newvectorchecked(S->L, n, Upvaldesc); f->sizeupvalues = n; - for (i = 0; i < n; i++) { + for (i = 0; i < n; i++) f->upvalues[i].name = NULL; + for (i = 0; i < n; i++) { f->upvalues[i].instack = loadByte(S); f->upvalues[i].idx = loadByte(S); f->upvalues[i].kind = loadByte(S);