Fixed detail in 'loadUpvalues' · lua/lua@422ce50 · GitHub
Skip to content

Commit 422ce50

Browse files
committed
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.
1 parent c33b172 commit 422ce50

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

‎lapi.c‎

Lines changed: 1 addition & 0 deletions

‎lundump.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,20 @@ static void loadProtos (LoadState *S, Proto *f) {
200200
}
201201

202202

203+
/*
204+
** Load the upvalues for a function. The names must be filled first,
205+
** because the filling of the other fields can raise read errors and
206+
** the creation of the error message can call an emergency collection;
207+
** in that case all prototypes must be consistent for the GC.
208+
*/
203209
static void loadUpvalues (LoadState *S, Proto *f) {
204210
int i, n;
205211
n = loadInt(S);
206212
f->upvalues = luaM_newvectorchecked(S->L, n, Upvaldesc);
207213
f->sizeupvalues = n;
208-
for (i = 0; i < n; i++) {
214+
for (i = 0; i < n; i++) /* make array valid for GC */
209215
f->upvalues[i].name = NULL;
216+
for (i = 0; i < n; i++) { /* following calls can raise errors */
210217
f->upvalues[i].instack = loadByte(S);
211218
f->upvalues[i].idx = loadByte(S);
212219
f->upvalues[i].kind = loadByte(S);

‎testes/calls.lua‎

Lines changed: 15 additions & 6 deletions

0 commit comments

Comments
 (0)