From 422ce50d2e8856ed789d1359c673122dbb0088ea Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 30 Jun 2020 15:36:26 -0300 Subject: Fixed detail in 'loadUpvalues' 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 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lundump.c') diff --git a/lundump.c b/lundump.c index 4243678a..cb124d6f 100644 --- a/lundump.c +++ b/lundump.c @@ -200,13 +200,20 @@ static void loadProtos (LoadState *S, Proto *f) { } +/* +** Load the upvalues for a function. The names must be filled first, +** because the filling of the other fields can raise read errors and +** the creation of the error message can call an emergency collection; +** in that case all prototypes must be consistent for the GC. +*/ static void loadUpvalues (LoadState *S, Proto *f) { int i, n; 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++) /* make array valid for GC */ f->upvalues[i].name = NULL; + for (i = 0; i < n; i++) { /* following calls can raise errors */ f->upvalues[i].instack = loadByte(S); f->upvalues[i].idx = loadByte(S); f->upvalues[i].kind = loadByte(S); -- cgit v1.2.3-55-g6feb