lua-users home
lua-l archive

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


I checked a new version 5.3.5 of Lua and found overflow bug in four functions.
The older versions of Lua also contain this error.

Affected functions.
lauxlib.c
   int countlevels (lua_State *L)

ltable.c
   int unbound_search (Table *t, unsigned int j) 
   int luaH_getn (Table *t);

ltabllib.c
   void auxsort (lua_State *L, TabA *ta, int l, int u)

The bug is very common. This equation leads overflow.
m = (h + l) / 2;

The equation should be rewritten as:
m = l + (h - l) / 2;

https://stackoverflow.com/questions/6735259/calculating-mid-in-binary-search