8000 numpy.zeros((0, 2**31-1)) crashes on 32 bit Python · Issue #7813 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
numpy.zeros((0, 2**31-1)) crashes on 32 bit Python #7813
Closed
@cgohlke

Description

@cgohlke

Using numpy-1.11.1 built with Visual Studio 2008/2010 for 32 bit Python 2.7/3.4 on Windows, the following code crashes in multiarray.pyd:

>>> import numpy
>>> numpy.zeros((0, 2**31-1))   # boom

The crash comes from calloc(size, elsize), where size=4294967288.

Call stack:

    msvcr90.dll!_crt_debugger_hook(int _Reserved) Line 65   C
    msvcr90.dll!_invoke_watson(const wchar_t * pszExpression, const wchar_t * pszFunction, const wchar_t * pszFile, unsigned int nLine, unsigned int pReserved) Line 230    C++
    msvcr90.dll!_calloc_impl(unsigned int num, unsigned int size, int * errno_tmp) Line 30  C
    msvcr90.dll!calloc(unsigned int num, unsigned int size) Line 50 C
>   multiarray.pyd!PyDataMem_NEW_ZEROED(unsigned int size, unsigned int elsize) Line 194    C
    multiarray.pyd!npy_alloc_cache_zero(unsigned int sz) Line 86    C
    multiarray.pyd!PyArray_NewFromDescr_int(_typeobject * subtype, _PyArray_Descr * descr, int nd, int * dims, int * strides, void * data, int flags, _object * obj, int zeroed) Line 1051  C
    multiarray.pyd!PyArray_Zeros(int nd, int * dims, _PyArray_Descr * type, int is_f_order) Line 2860   C
    multiarray.pyd!array_zeros(_object * __NPY_UNUSED_TAGGEDignored, _object * args, _object * kwds) Line 1969  C
5CE4

    python27.dll!PyCFunction_Call(_object * func, _object * arg, _object * kw) Line 85  C
    python27.dll!call_function(_object * * * pp_stack, int oparg) Line 4350 C
    python27.dll!PyEval_EvalFrameEx(_frame * f, int throwflag) Line 2990    C
    python27.dll!PyEval_EvalCodeEx(PyCodeObject * co, _object * globals, _object * locals, _object * * args, int argcount, _object * * kws, int kwcount, _object * * defs, int defcount, _object * closure) Line 3582   C
    python27.dll!run_mod(_mod * mod, const char * filename, _object * globals, _object * locals, PyCompilerFlags * flags, _arena * arena) Line 1376 C
    python27.dll!PyRun_InteractiveOneFlags(_iobuf * fp, const char * filename, PyCompilerFlags * flags) Line 857    C
    python27.dll!PyRun_InteractiveLoopFlags(_iobuf * fp, const char * filename, PyCompilerFlags * flags) Line 777   C
    python27.dll!PyRun_AnyFileExFlags(_iobuf * fp, const char * filename, int closeit, PyCompilerFlags * flags) Line 746    C
    python27.dll!Py_Main(int argc, char * * argv) Line 643  C
    python.exe!__tmainCRTStartup() Line 586 C
    [External Code] 

numpy compiled with Visual Studio 2015 for 32 bit Python 3.5 raises a MemoryError:

>>> import numpy
>>> numpy.zeros((0, 2**31-1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError

64 bit binaries return an empty array as expected:

>>> import numpy
>>> numpy.zeros((0, 2**31-1))
array([], shape=(0L, 2147483647L), dtype=float64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0