1- # Copyright (C) 2021 Raven Computing
1+ # Copyright (C) 2022 Raven Computing
22#
33# Licensed under the Apache License, Version 2.0 (the "License");
44# you may not use this file except in compliance with the License.
@@ -947,6 +947,10 @@ def setitem_impl(arg, position, value):
947947
948948 rows = rows % arg .rows ()
949949
950+ if rows >= arg .rows ():
951+ raise dataframe .DataFrameException (
952+ "Invalid row index: {}" .format (rows ))
953+
950954 if isinstance (value , (tuple , list )):
951955 # implements df[(x0, x1, ..., xn), y] = [v0, v1, ..., vn]
952956 # and df[x0:x1:x2, y] = [v0, v1, ..., vn]
@@ -965,6 +969,7 @@ def setitem_impl(arg, position, value):
965969 ("Invalid value argument. The specified list/tuple "
966970 "of row values is empty" ))
967971
972+ nrows = arg .rows () # cache the number of rows
968973 if isinstance (value [0 ], (list , tuple )):
969974 if len (rows ) != len (value ):
970975 raise dataframe .DataFrameException (
@@ -973,9 +978,21 @@ def setitem_impl(arg, position, value):
973978 "has a size of {}" ).format (len (value ), len (rows )))
974979
975980 for i , index in enumerate (rows ):
981+ # safety bounds check
982+ if index >= nrows :
983+ raise dataframe .DataFrameException (
984+ "Invalid row index within "
985+ "specified sequence: {}" .format (index ))
986+
976987 cols_selected .set_row (index , value [i ])
977988 else :
978989 for index in rows :
990+ # safety bounds check
991+ if index >= nrows :
992+ raise dataframe .DataFrameException (
993+ "Invalid row index within "
994+ "specified sequence: {}" .format (index ))
995+
979996 cols_selected .set_row (index , value )
980997
981998 elif isinstance (value , dataframe .DataFrame ):
0 commit comments