lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, May 31, 2020 at 2:31 PM Coda Highland <chighland@gmail.com> wrote:
>
> On Sun, May 31, 2020 at 1:19 PM Joseph C. Sible <josephcsible@gmail.com> wrote:
>>
>> I'm not sure, though, whether this is a bug in Lua, or just that
>> you're not supposed to use lua_resume on the main thread.
>
> I'm reasonably certain you're not supposed to. The main thread is something of a special case. It isn't a coroutine and it has responsibilities that coroutines don't. (You can't, for example, close the main thread and expect its coroutines to continue working.)
>
> Honestly I would have been surprised if it DID work, and I wouldn't have relied on it in practice because that sounds more like taking advantage of an implementation detail than an intended behavior.

Out of curiosity, I tracked down the cause of this with Clang's UBSan
and MSan. When lua_getinfo called swapextra, ci->extra was never
initialized, so ci->func ended up pointing to random memory. Then,
when lua_getinfo did ttisclosure(func), it tried to read that random
memory, which caused the segfault.

Also, I tried the same thing with 5.2.4 and 5.4.0rc3. Like the OP, I
can't reproduce it with 5.4, and UBSan and MSan also don't see
anything wrong there. However, unlike the OP, I can reproduce it with
5.2. This makes it seem plausible that this was a legitimate bug that
5.4 fixed.

Joseph C. Sible