diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-06-30 15:36:26 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-06-30 15:36:26 -0300 |
commit | 422ce50d2e8856ed789d1359c673122dbb0088ea (patch) | |
tree | 163c566c322915b12d13e4b1d1966d5658e19086 /testes | |
parent | c33b1728aeb7dfeec4013562660e07d32697aa6b (diff) | |
download | lua-422ce50d2e8856ed789d1359c673122dbb0088ea.tar.gz lua-422ce50d2e8856ed789d1359c673122dbb0088ea.tar.bz2 lua-422ce50d2e8856ed789d1359c673122dbb0088ea.zip |
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.
Diffstat (limited to 'testes')
-rw-r--r-- | testes/calls.lua | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/testes/calls.lua b/testes/calls.lua index 1701f155..decf4176 100644 --- a/testes/calls.lua +++ b/testes/calls.lua | |||
@@ -422,20 +422,30 @@ assert((function (a) return a end)() == nil) | |||
422 | 422 | ||
423 | print("testing binary chunks") | 423 | print("testing binary chunks") |
424 | do | 424 | do |
425 | local header = string.pack("c4BBc6BBBj", | 425 | local header = string.pack("c4BBc6BBB", |
426 | "\27Lua", -- signature | 426 | "\27Lua", -- signature |
427 | 0x54, -- version 5.4 (0x54) | 427 | 0x54, -- version 5.4 (0x54) |
428 | 0, -- format | 428 | 0, -- format |
429 | "\x19\x93\r\n\x1a\n", -- data | 429 | "\x19\x93\r\n\x1a\n", -- data |
430 | 4, -- size of instruction | 430 | 4, -- size of instruction |
431 | string.packsize("j"), -- sizeof(lua integer) | 431 | string.packsize("j"), -- sizeof(lua integer) |
432 | string.packsize("n"), -- sizeof(lua number) | 432 | string.packsize("n") -- sizeof(lua number) |
433 | 0x5678 -- LUAC_INT | ||
434 | -- LUAC_NUM may not have a unique binary representation (padding...) | ||
435 | ) | 433 | ) |
436 | local c = string.dump(function () local a = 1; local b = 3; return a+b*3 end) | 434 | local c = string.dump(function () |
435 | local a = 1; local b = 3; | ||
436 | local f = function () return a + b + _ENV.c; end -- upvalues | ||
437 | local s1 = "a constant" | ||
438 | local s2 = "another constant" | ||
439 | return a + b * 3 | ||
440 | end) | ||
437 | 441 | ||
442 | assert(assert(load(c))() == 10) | ||
443 | |||
444 | -- check header | ||
438 | assert(string.sub(c, 1, #header) == header) | 445 | assert(string.sub(c, 1, #header) == header) |
446 | -- check LUAC_INT and LUAC_NUM | ||
447 | local ci, cn = string.unpack("jn", c, #header + 1) | ||
448 | assert(ci == 0x5678 and cn == 370.5) | ||
439 | 449 | ||
440 | -- corrupted header | 450 | -- corrupted header |
441 | for i = 1, #header do | 451 | for i = 1, #header do |
@@ -451,7 +461,6 @@ do | |||
451 | local st, msg = load(string.sub(c, 1, i)) | 461 | local st, msg = load(string.sub(c, 1, i)) |
452 | assert(not st and string.find(msg, "truncated")) | 462 | assert(not st and string.find(msg, "truncated")) |
453 | end | 463 | end |
454 | assert(assert(load(c))() == 10) | ||
455 | end | 464 | end |
456 | 465 | ||
457 | print('OK') | 466 | print('OK') |