nasa / EdsLib

CCSDS SOIS Electronic Data Sheet Tool and Library
Apache License 2.0
31 stars 12 forks source link

EdsLib_LuaBinding_EncodeObject() API limited to 8KiB object size, undefined behavior if exceeded #29

Closed jphickey closed 1 year ago

jphickey commented 1 year ago

The conversion uses a LuaL_Buffer to temporarily hold the output object. The capacity of this object depends on Lua compile time configuration LUAL_BUFFERSIZE, which defaults to 8192 bytes.

The call to this function will (properly) fail if the buffer is too small: https://github.com/nasa/EdsLib/blob/7dac5fd76bc08c4b40d09be47a0c4376e162581e/edslib/lua/src/edslib_lua_objects.c#L756

However, the result is not checked, and it still calls luaL_addsize with the too-large size and attempts to push the result, which is invalid.

This causes problems when attempting to generate tables for LC and DS. For example LC has a table that is about 17kB in size.