@@ -159,6 +159,10 @@ static NewReference NewInstance(Type elementType, BorrowedReference arrayPyType,
159
159
160
160
if ( rank == 1 )
161
161
{
162
+ if ( ! Runtime . PyInt_Check ( idx ) )
163
+ {
164
+ return Exceptions . RaiseTypeError ( "array index is not an integer" ) ;
165
+ }
162
166
index = Runtime . PyInt_AsLong ( idx ) ;
163
167
164
168
if ( Exceptions . ErrorOccurred ( ) )
@@ -199,6 +203,10 @@ static NewReference NewInstance(Type elementType, BorrowedReference arrayPyType,
199
203
for ( var i = 0 ; i < count ; i ++ )
200
204
{
201
205
IntPtr op = Runtime . PyTuple_GetItem ( idx , i ) ;
206
+ if ( ! Runtime . PyInt_Check ( op ) )
207
+ {
208
+ return Exceptions . RaiseTypeError ( $ "array index { i } is not an integer") ;
209
+ }
202
210
index = Runtime . PyInt_AsLong ( op ) ;
203
211
204
212
if ( Exceptions . ErrorOccurred ( ) )
@@ -253,6 +261,11 @@ static NewReference NewInstance(Type elementType, BorrowedReference arrayPyType,
253
261
254
262
if ( rank == 1 )
255
263
{
264
+ if ( ! Runtime . PyInt_Check ( idx ) )
265
+ {
266
+ Exceptions . RaiseTypeError ( "array index is not an integer" ) ;
267
+ return - 1 ;
268
+ }
256
269
index = Runtime . PyInt_AsLong ( idx ) ;
257
270
258
271
if ( Exceptions . ErrorOccurred ( ) )
@@ -291,6 +304,11 @@ static NewReference NewInstance(Type elementType, BorrowedReference arrayPyType,
291
304
for ( var i = 0 ; i < count ; i ++ )
292
305
{
293
306
IntPtr op = Runtime . PyTuple_GetItem ( idx , i ) ;
307
+ if ( ! Runtime . PyInt_Check ( op ) )
308
+ {
309
+ Exceptions . RaiseTypeError ( $ "array index { i } is not an integer") ;
310
+ return - 1 ;
311
+ }
294
312
index = Runtime . PyInt_AsLong ( op ) ;
295
313
296
314
if ( Exceptions . ErrorOccurred ( ) )
0 commit comments