Skip to content

Commit bdcc69d

Browse files
Fix Lua Integer Overflow (CVE-2025-46817)
1 parent 6d75b16 commit bdcc69d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

app/redis-6.2.6/deps/lua/src/lbaselib.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,14 @@ static int luaB_assert (lua_State *L) {
340340

341341

342342
static int luaB_unpack (lua_State *L) {
343-
int i, e, n;
343+
int i, e;
344+
unsigned int n;
344345
luaL_checktype(L, 1, LUA_TTABLE);
345346
i = luaL_optint(L, 2, 1);
346347
e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1));
347348
if (i > e) return 0; /* empty range */
348-
n = e - i + 1; /* number of elements */
349-
if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
349+
n = (unsigned int)e - (unsigned int)i; /* number of elements minus 1 */
350+
if (n >= INT_MAX || !lua_checkstack(L, ++n))
350351
return luaL_error(L, "too many results to unpack");
351352
lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
352353
while (i++ < e) /* push arg[i + 1...e] */

0 commit comments

Comments
 (0)