Open shripchenko opened 8 years ago
I've run into the same issue and discovered it is alleviated by downgrading to version 2.3.0. It looks like the changes in 2.3.1 introducing the segfault-related code.
The issue is that fallback implementation of luaL_buffinitsize
calls luaL_prepbuffer
instead of luaL_prepbuffsize
. luaL_prepbuffer
is equivalent to luaL_prepbuffsize
with buffer size LUAL_BUFFERSIZE
(8192). Incidentally, feature detection is invalid (luaL_buffinitsize
is not a macro), which makes this bug appear even for Lua 5.2 and 5.3.
Fixed on master branch.
@mpeterv: Please be aware that your use of luaL_prepbuffsize
in 6316be8d0fa241657b4d337f29c4b740452c2dc9 breaks backward compatibility with Lua 5.1. Up until this point LuaSQL, including 2.3.3, worked fine with Lua 5.1. I'm not sure if a decision to deprecate 5.1 support was made after the 2.3.3 release, but I thought you'd like be aware.
For what it's worth, my use case for LuaSQL was as a dependency to a Mozilla Heka output plugin, and the latest release of Heka (0.10.0) still relies on Lua 5.1 for its sandboxes, so for now I'll have to continue using LuaSQL 2.3.0 to work around the problem.
@joell, sorry, that was unintentional.
@tomasguisasola if malloc
can't be avoided while maintaining correctness @4acc737 should be (partially) reverted, right?
couldn't one just use lua_newuserdata
instead of malloc
to allocate the memory that's temporarily needed there and just leave it to the Lua GC to collect it?
lua_newuserdata is not the correct choice. The lua string bufer is (http://www.lua.org/manual/5.3/manual.html#luaL_Buffer).
I think now it is correctly used and it is working with Lua 5.1, 5.2 and 5.3. I couldn't check it with Lua 5.0, but will try... I would be glad if both joell and mpeterv could try this new version: 2.3.4. Let me know whether it is working!
This sample script
will be failed after
s1=4099, s2=8198
iteration and generate either SIGSEGV, or random error like:some insights after brief looking to code:
luaL_Buffer b;
- default buffer size of 8192char *to = luaL_buffinitsize (L, &b, 2*len+1);
- not checking actual returned buffer sizeluaL_buffinit (L, &b);
- init buffer with default size of 8192 regardles oflen
len = PQescapeStringConn (conn->pg_conn, to, from, len, &error);
-len
parameter does not take into account an actual buffer sizeEnvironment: