File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -671,10 +671,17 @@ PyArray_ConcatenateInto(PyObject *op,
671
671
}
672
672
673
673
/* Convert the input list into arrays */
674
- narrays = PySequence_Size (op );
675
- if (narrays < 0 ) {
674
+ Py_ssize_t narrays_true = PySequence_Size (op );
675
+ if (narrays_true < 0 ) {
676
676
return NULL ;
677
677
}
678
+ else if (narrays_true > NPY_MAX_INT ) {
679
+ PyErr_Format (PyExc_ValueError ,
680
+ "concatenate() only supports up to %d arrays but got %zd." ,
681
+ NPY_MAX_INT , narrays_true );
682
+ return NULL ;
683
+ }
684
+ narrays = (int )narrays_true ;
678
685
arrays = PyArray_malloc (narrays * sizeof (arrays [0 ]));
679
686
if (arrays == NULL ) {
680
687
PyErr_NoMemory ();
Original file line number Diff line number Diff line change
1
+ import sys
2
+
1
3
import pytest
2
4
3
5
import numpy as np
29
31
assert_raises ,
30
32
assert_raises_regex ,
31
33
)
34
+ from numpy .testing ._private .utils import requires_memory
32
35
33
36
34
37
class TestAtleast1d :
@@ -290,6 +293,17 @@ def test_exceptions(self):
290
293
# No arrays to concatenate raises ValueError
291
294
assert_raises (ValueError , concatenate , ())
292
295
296
+ @pytest .mark .slow
297
+ @pytest .mark .skipif (sys .maxsize < 2 ** 32 , reason = "only problematic on 64bit platforms" )
298
+ @requires_memory (2 * np .iinfo (np .intc ).max )
299
+ def test_huge_list_error (self ):
300
+ a = np .array ([1 ])
301
+ max_int = np .iinfo (np .intc ).max
302
+ arrs = (a ,) * (max_int + 1 )
303
+ msg = fr"concatenate\(\) only supports up to { max_int } arrays but got { max_int + 1 } ."
304
+ with pytest .raises (ValueError , match = msg ):
305
+ np .concatenate (arrs )
306
+
293
307
def test_concatenate_axis_None (self ):
294
308
a = np .arange (4 , dtype = np .float64 ).reshape ((2 , 2 ))
295
309
b = list (range (3 ))
You can’t perform that action at this time.
0 commit comments