Skip to content

Segmentation fault when 'size' argument to numpy.random.multinomial has type numpy.uint32. #3173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
saffsd opened this issue Mar 28, 2013 · 4 comments · Fixed by #4348
Closed

Comments

@saffsd
Copy link

saffsd commented Mar 28, 2013

Steps to reproduce:

Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import numpy as np
np.random.multinomial(1,[0.5,0.5],np.uint32(1))
array([0, 1, 1])
np.uint32(1)
1
np.random.multinomial(1,[0.5,0.5],np.uint32(1))
array([0, 1, 0])
np.random.multinomial(1,[0.5,0.5],np.uint32(1))
array([0, 1, 0])
np.random.multinomial(1,[0.5,0.5],np.uint32(1))
*** glibc detected *** python: free(): invalid next size (fast): 0x0000000001bbfb90 ***

It also seems that numpy.random.multinomial behaves incorrectly when the size argument is of type numpy.uint32 - in the above example, each vector is of length 3 whereas the expected behaviour is an array of length 2.

Some details about the platform:

numpy.version
'1.6.1'

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.1 LTS
Release: 12.04
Codename: precise

uname -ar
Linux mlui 3.2.0-38-generic #61-Ubuntu SMP Tue Feb 19 12:18:21 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

@saffsd
Copy link
Author

saffsd commented Mar 28, 2013

Full trace:

*** glibc detected *** python: free(): invalid next size (fast): 0x0000000001b646c0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7f4d190b5b96]
/usr/lib/python2.7/dist-packages/numpy/core/multiarray.so(+0x8d566)[0x7f4d1826c566]
python[0x57cbd5]
python(PyDict_SetItem+0x49)[0x4faf79]
python(_PyObject_GenericSetAttrWithDict+0x12b)[0x4fd4ab]
python(PyObject_SetAttr+0x6d)[0x4fd71d]
python(PyObject_SetAttrString+0x63)[0x4fde33]
python[0x560f63]
python(PyObject_Call+0x36)[0x4e9f36]
python(PyEval_CallObjectWithKeywords+0x36)[0x4ea396]
python(PyEval_EvalFrameEx+0x35a9)[0x49b1a9]
python(PyEval_EvalCodeEx+0x1a0)[0x49f1c0]
python(PyRun_InteractiveOneFlags+0x26f)[0x4a9d0f]
python(PyRun_InteractiveLoopFlags+0x145)[0x4aa075]
python(PyRun_AnyFileExFlags+0xa8)[0x4aa328]
python(Py_Main+0x55d)[0x4aa8bd]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7f4d1905876d]
python[0x41b9b1]
======= Memory map: ========
00400000-00671000 r-xp 00000000 08:01 3282492 /usr/bin/python2.7
00870000-00871000 r--p 00270000 08:01 3282492 /usr/bin/python2.7
00871000-008da000 rw-p 00271000 08:01 3282492 /usr/bin/python2.7
008da000-008ec000 rw-p 00000000 00:00 0
0130d000-01c81000 rw-p 00000000 00:00 0 [heap]
7f4d145ce000-7f4d146b0000 r-xp 00000000 08:01 3277459 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7f4d146b0000-7f4d148af000 ---p 000e2000 08:01 3277459 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7f4d148af000-7f4d148b7000 r--p 000e1000 08:01 3277459 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7f4d148b7000-7f4d148b9000 rw-p 000e9000 08:01 3277459 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7f4d148b9000-7f4d148ce000 rw-p 00000000 00:00 0
7f4d148ce000-7f4d149ef000 r-xp 00000000 08:01 3278281 /usr/lib/x86_64-linux-gnu/libapt-pkg.so.4.12.0
7f4d149ef000-7f4d14bef000 ---p 00121000 08:01 3278281 /usr/lib/x86_64-linux-gnu/libapt-pkg.so.4.12.0
7f4d14bef000-7f4d14bf3000 r--p 00121000 08:01 3278281 /usr/lib/x86_64-linux-gnu/libapt-pkg.so.4.12.0
7f4d14bf3000-7f4d14bf4000 rw-p 00125000 08:01 3278281 /usr/lib/x86_64-linux-gnu/libapt-pkg.so.4.12.0
7f4d14bf4000-7f4d14bf5000 rw-p 00000000 00:00 0
7f4d14bf5000-7f4d14c3f000 r-xp 00000000 08:01 3284847 /usr/lib/python2.7/dist-packages/apt_pkg.so
7f4d14c3f000-7f4d14e3f000 ---p 0004a000 08:01 3284847 /usr/lib/python2.7/dist-packages/apt_pkg.so
7f4d14e3f000-7f4d14e41000 r--p 0004a000 08:01 3284847 /usr/lib/python2.7/dist-packages/apt_pkg.so
7f4d14e41000-7f4d14e4a000 rw-p 0004c000 08:01 3284847 /usr/lib/python2.7/dist-packages/apt_pkg.so
7f4d14e4a000-7f4d14e69000 r-xp 00000000 08:01 3317841 /usr/lib/python2.7/lib-dynload/_io.so
7f4d14e69000-7f4d15068000 ---p 0001f000 08:01 3317841 /usr/lib/python2.7/lib-dynload/_io.so
7f4d15068000-7f4d15069000 r--p 0001e000 08:01 3317841 /usr/lib/python2.7/lib-dynload/_io.so
7f4d15069000-7f4d15072000 rw-p 0001f000 08:01 3317841 /usr/lib/python2.7/lib-dynload/_io.so
7f4d15072000-7f4d15099000 r-xp 00000000 08:01 4984443 /lib/x86_64-linux-gnu/libexpat.so.1.5.2
7f4d15099000-7f4d15299000 ---p 00027000 08:01 4984443 /lib/x86_64-linux-gnu/libexpat.so.1.5.2
7f4d15299000-7f4d1529b000 r--p 00027000 08:01 4984443 /lib/x86_64-linux-gnu/libexpat.so.1.5.2
7f4d1529b000-7f4d1529c000 rw-p 00029000 08:01 4984443 /lib/x86_64-linux-gnu/libexpat.so.1.5.2
7f4d1529c000-7f4d152aa000 r-xp 00000000 08:01 3317849 /usr/lib/python2.7/lib-dynload/pyexpat.so
7f4d152aa000-7f4d154a9000 ---p 0000e000 08:01 3317849 /usr/lib/python2.7/lib-dynload/pyexpat.so
7f4d154a9000-7f4d154aa000 r--p 0000d000 08:01 3317849 /usr/lib/python2.7/lib-dynload/pyexpat.so
7f4d154aa000-7f4d154ac000 rw-p 0000e000 08:01 3317849 /usr/lib/python2.7/lib-dynload/pyexpat.so
7f4d154ac000-7f4d154cd000 r-xp 00000000 08:01 3317840 /usr/lib/python2.7/lib-dynload/_ctypes.so
7f4d154cd000-7f4d156cc000 ---p 00021000 08:01 3317840 /usr/lib/python2.7/lib-dynload/_ctypes.so
7f4d156cc000-7f4d156cd000 r--p 00020000 08:01 3317840 /usr/lib/python2.7/lib-dynload/_ctypes.so
7f4d156cd000-7f4d156d1000 rw-p 00021000 08:01 3317840 /usr/lib/python2.7/lib-dynload/_ctypes.so
7f4d156d1000-7f4d156d2000 rw-p 00000000 00:00 0
7f4d156d2000-7f4d15714000 r-xp 00000000 08:01 4066482 /usr/lib/python2.7/dist-packages/numpy/random/mtrand.so
7f4d15714000-7f4d15913000 ---p 00042000 08:01 4066482 /usr/lib/python2.7/dist-packages/numpy/random/mtrand.so
7f4d15913000-7f4d15914000 r--p 00041000 08:01 4066482 /usr/lib/python2.7/dist-packages/numpy/random/mtrand.so
7f4d15914000-7f4d15949000 rw-p 00042000 08:01 4066482 /usr/lib/python2.7/dist-packages/numpy/random/mtrand.so
7f4d15949000-7f4d15952000 r-xp 00000000 08:01 4066387 /usr/lib/python2.7/dist-packages/numpy/fft/fftpack_lite.so
7f4d15952000-7f4d15b51000 ---p 00009000 08:01 4066387 /usr/lib/python2.7/dist-packages/numpy/fft/fftpack_lite.so
7f4d15b51000-7f4d15b52000 r--p 00008000 08:01 4066387 /usr/lib/python2.7/dist-packages/numpy/fft/fftpack_lite.so
7f4d15b52000-7f4d15b53000 rw-p 00009000 08:01 4066387 /usr/lib/python2.7/dist-packages/numpy/fft/fftpack_lite.so
7f4d15b53000-7f4d1645e000 r-xp 00000000 08:01 3320428 /usr/lib/atlas-base/atlas/liblapack.so.3gf.0
7f4d1645e000-7f4d1665e000 ---p 0090b000 08:01 3320428 /usr/lib/atlas-base/atlas/liblapack.so.3gf.0
7f4d1665e000-7f4d16663000 rw-p 0090b000 08:01 3320428 /usr/lib/atlas-base/atlas/liblapack.so.3gf.0
7f4d16663000-7f4d16770000 rw-p 00000000 00:00 0
7f4d16770000-7f4d16775000 r-xp 00000000 08:01 4066409 /usr/lib/python2.7/dist-packages/numpy/linalg/lapack_lite.so
7f4d16775000-7f4d16975000 ---p 00005000 08:01 4066409 /usr/lib/python2.7/dist-packages/numpy/linalg/lapack_lite.so
7f4d16975000-7f4d16976000 r--p 00005000 08:01 4066409 /usr/lib/python2.7/dist-packages/numpy/linalg/lapack_lite.sozsh: abort (core dumped) python

@charris
Copy link
Member

charris commented Feb 15, 2014

Still present in 1.9-devel

@juliantaylor
Copy link
Contributor

uint32 does not trigger the int path in the shape definition

        if size is None:
            shape = (d,) 
        elif type(size) is int: 
            shape = (size, d)
        else:
            shape = size + (d,) 

np.uint32(1)+(2,) is a apparently array([3])
shouldn't that raise an exception like floats do?

@seberg
Copy link
Member

seberg commented Feb 15, 2014

All numpy types define these as array operations... That is not clean, I agree, but I am a bit unsure if we can simply change it because after all almost all numpy operation will make scalars from 0-d arrays.

One of those annoying how to best check for an integer thing :). One of these days maybe we should expose the C-api until then, a try/except for either tuple(size) or operator.index(size) may be an option? Of course if someone knows a better method...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants