lua-users home
lua-l archive

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


I'm fairly sure that it's not FILE that's NULL, because the 0x2 offset wouldn't align with anything in the FILE struct - I think it needs to be the destination pointer that's NULL.

It's interesting that of the handful of "weird" crash logs I get, all of them are where one of our C callbacks is called by the OS and we pcall() into Lua. To me that definitely adds to the "this is a lifecycle thing". I've put in place quite a few protections already to try and make sure those things only happen when lua_State is consistent, but perhaps I am still missing something.

On Thu, 11 Mar 2021 at 02:03, Ranier Vilela <ranier.vf@gmail.com> wrote:
Em qua., 10 de mar. de 2021 às 06:44, Chris Jones <cmsj@tenshu.net> escreveu:
Thanks Robert, that makes sense, so the user seems to be calling either io.read(), or :read() on an io object.

So taking that as legitimate, I'm now trying to explain the "garbage pointer 0x2" in fread(). Its signature is:

size_t fread(void *restrict ptr, size_t size, size_t nitems, FILE *restrict stream);

My first thought was maybe it's the FILE that's NULL and something inside it at offset 0x2 is what is being access, but the first field is a pointer, ie 8 bytes, making that unlikely.

So, then maybe it's the destination buffer that's the problem?

read_all() calls luaL_prepbuffer() right before fread(), to prepare the destination buffer, and that calls through to prepbuffsize() which appears to be doing pointer math on a luaL_Buffer struct, specifically foo->b + foo->n, so if b is NULL and n is 2 then we have a plausible path to the 0x2 error.

The question then becomes, how can foo->b be NULL?

Looking at prepbuffsize() I see three paths through the function, and I'm not sure I can rule any of them out as being incapable of producing a NULL.

Either way, I'm still not familiar enough with the Lua code to know how the buffer address could end up being NULL. Any ideas?
As I suspected.

Keeping It Simple

Whenever you encounter EXC_BAD_ACCESS, it means that you are sending a message to an object that has already been released.

This is the most common scenario, but there are exceptions as we'll discuss in a moment.

https://code.tutsplus.com/tutorials/what-is-exc_bad_access-and-how-to-debug-it--cms-24544

fread is calling with probably FILE var already released.

regards,
Ranier Vilela


--
Cheers,

Chris