@@ -707,8 +707,10 @@ static void luau_execute(lua_State* L)
707707 {
708708 LuaTable* h = hvalue (rb);
709709
710+ // ServerLua: Use luai_num2int for UBSan suppression in ASAN builds
710711 double indexd = nvalue (rc);
711- int index = int (indexd);
712+ int index;
713+ luai_num2int (index, indexd);
712714
713715 // index has to be an exact integer and in-bounds for the array portion
714716 if (LUAU_LIKELY (unsigned (index) - 1 < unsigned (h->sizearray ) && !h->metatable && double (index) == indexd))
@@ -748,8 +750,10 @@ static void luau_execute(lua_State* L)
748750 {
749751 LuaTable* h = hvalue (rb);
750752
753+ // ServerLua: Use luai_num2int for UBSan suppression in ASAN builds
751754 double indexd = nvalue (rc);
752- int index = int (indexd);
755+ int index;
756+ luai_num2int (index, indexd);
753757
754758 // index has to be an exact integer and in-bounds for the array portion
755759 if (LUAU_LIKELY (unsigned (index) - 1 < unsigned (h->sizearray ) && !h->metatable && !h->readonly && double (index) == indexd))
@@ -1856,7 +1860,9 @@ static void luau_execute(lua_State* L)
18561860 {
18571861 // ServerLua: division by -1 is weird, and
18581862 // previously special-cased to prevent division errors.
1859- setintvalue (ra, -1 * intvalue (rb));
1863+ // Note: -INT32_MIN overflows, so handle that case explicitly.
1864+ int32_t val = intvalue (rb);
1865+ setintvalue (ra, val == INT32_MIN ? INT32_MIN : -val);
18601866 }
18611867 else
18621868 {
@@ -2148,7 +2154,9 @@ static void luau_execute(lua_State* L)
21482154 {
21492155 // ServerLua: division by -1 is weird, and
21502156 // previously special-cased to prevent division errors.
2151- setintvalue (ra, -1 * intvalue (rb));
2157+ // Note: -INT32_MIN overflows, so handle that case explicitly.
2158+ int32_t val = intvalue (rb);
2159+ setintvalue (ra, val == INT32_MIN ? INT32_MIN : -val);
21522160 }
21532161 else
21542162 {
0 commit comments