This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Pythong seg fault with PIL/numpy
Type: crash Stage:
Components: Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: David.Knapp, brett.cannon, pitrou
Priority: normal Keywords:

Created on 2011-02-13 21:56 by David.Knapp, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg128523 - (view) Author: David Knapp (David.Knapp) Date: 2011-02-13 21:56
Python had a seg fault with the following simple code.

>>> import PIL.Image as Img
>>> import numpy as np
>>> i = Img.open('/home/falmarri/Dropbox/obey.jpg')
>>> n = np.array(bytearray(i.tostring()),dtype=np.uint16)
zsh: segmentation fault  python

Running it under gdb gave the following

(gdb) run g19_framebuffer.py
Starting program: /usr/bin/python g19_framebuffer.py
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
_unaligned_strided_byte_copy (dst=0xcb9543 "\366\377\177", outstrides=1, src=0x7ffff3503da5 <Address 0x7ffff3503da5 out of bounds>, 
    instrides=4969607, N=10000, elsize=<value optimized out>) at /usr/include/bits/string3.h:52
warning: Source file is more recent than executable.
52        return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));


It could be that I'm doing it wrong though.
msg128524 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2011-02-13 21:59
Can you give a longer backtrace? Since that failure is happening in a system library we need to know where the segfault first occurs in either PIL, numpy, or CPython.

And have you tried this in Python 2.7?
msg128531 - (view) Author: David Knapp (David.Knapp) Date: 2011-02-14 00:07
Sorry I'm not all that experienced with gdb. Let me know if there's more to get.

(gdb) bt
#0  _unaligned_strided_byte_copy (dst=0xcb9623 "\366\377\177", outstrides=1, src=
    0x7ffff3503da5 <Address 0x7ffff3503da5 out of bounds>, instrides=4969607, N=10000, elsize=<value optimized out>)
    at /usr/include/bits/string3.h:52
#1  0x00007ffff5ee2cca in _strided_buffered_cast (dptr=<value optimized out>, dstride=<value optimized out>, 
    delsize=<value optimized out>, dswap=<value optimized out>, dcopyfunc=<value optimized out>, sptr=<value optimized out>, 
    sstride=4969607, selsize=1, sswap=0, scopyfunc=0x7ffff5eec340 <UBYTE_copyswapn>, N=10000, buffers=0x7fffffffd7d0, 
    bufsize=10000, castfunc=0x7ffff5edbf30 <UBYTE_to_USHORT>, dest=0x9634a0, src=0xa3d7e0)
    at numpy/core/src/multiarray/convert_datatype.c:164
#2  0x00007ffff5ee2c66 in _strided_buffered_cast (dptr=<value optimized out>, dstride=<value optimized out>, 
    delsize=<value optimized out>, dswap=<value optimized out>, dcopyfunc=<value optimized out>, sptr=<value optimized out>, 
    sstride=4969607, selsize=1, sswap=0, scopyfunc=0x7ffff5eec340 <UBYTE_copyswapn>, N=13039280, buffers=0x7fffffffd7d0, 
    bufsize=10000, castfunc=0x7ffff5edbf30 <UBYTE_to_USHORT>, dest=0x9634a0, src=0xa3d7e0)
    at numpy/core/src/multiarray/convert_datatype.c:175
#3  0x00007ffff5f13337 in _broadcast_cast (out=0x9634a0, in=0xa3d7e0, castfunc=<value optimized out>, iswap=<value optimized out>, 
    oswap=<value optimized out>) at numpy/core/src/multiarray/convert_datatype.c:255
#4  0x00007ffff5f14e48 in _array_copy_into (dest=0x9634a0, src=0xa3d7e0, usecopy=<value optimized out>)
    at numpy/core/src/multiarray/ctors.c:861
#5  0x00007ffff5f16d3b in PyArray_FromArray (arr=0xa3d7e0, newtype=<value optimized out>, flags=<value optimized out>)
    at numpy/core/src/multiarray/ctors.c:2021
#6  0x00007ffff5f0f4ae in PyArray_FromAny (op=<bytearray at remote 0xb869f0>, newtype=0x7ffff61527e0, min_depth=0, max_depth=0, 
    flags=112, context=<value optimized out>) at numpy/core/src/multiarray/ctors.c:1785
#7  0x00007ffff5f214e6 in PyArray_CheckFromAny (op=<bytearray at remote 0xb869f0>, descr=0x7ffff61527e0, min_depth=-212845147, 
    max_depth=228, requires=112, context=<unknown at remote 0x1>) at numpy/core/src/multiarray/ctors.c:1934
#8  0x00007ffff5f2283a in _array_fromobject (__NPY_UNUSED_TAGGEDignored=<value optimized out>, args=<value optimized out>, 
    kws=<value optimized out>) at numpy/core/src/multiarray/multiarraymodule.c:1500
#9  0x00000000004a5ce4 in do_call (f=Frame 0x91ac90, for file g19_framebuffer.py, line 121, in <module> (), 
    throwflag=<value optimized out>) at ../Python/ceval.c:3965
#10 call_function (f=Frame 0x91ac90, for file g19_framebuffer.py, line 121, in <module> (), throwflag=<value optimized out>)
    at ../Python/ceval.c:3773
#11 PyEval_EvalFrameEx (f=Frame 0x91ac90, for file g19_framebuffer.py, line 121, in <module> (), throwflag=<value optimized out>)
    at ../Python/ceval.c:2412
#12 0x00000000004a6bd1 in PyEval_EvalCodeEx (co=0x7ffff7f06a80, globals=<value optimized out>, locals=<value optimized out>, args=
    0x0, argcount=<value optimized out>, kws=<value optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0)
    at ../Python/ceval.c:3000
#13 0x00000000004a6ca2 in PyEval_EvalCode (co=0xcb9623, globals=<unknown at remote 0x1>, locals=<unknown at remote 0x7ffff3503da5>)
    at ../Python/ceval.c:541
#14 0x00000000004c702e in run_mod (fp=<value optimized out>, filename=0x7fffffffe232 "g19_framebuffer.py", 
    start=<value optimized out>, globals=<value optimized out>, locals=<value optimized out>, closeit=1, flags=0x7fffffffde30)
    at ../Python/pythonrun.c:1351
#15 PyRun_FileExFlags (fp=<value optimized out>, filename=0x7fffffffe232 "g19_framebuffer.py", start=<value optimized out>, 
    globals=<value optimized out>, locals=<value optimized out>, closeit=1, flags=0x7fffffffde30) at ../Python/pythonrun.c:1337
#16 0x00000000004c7244 in PyRun_SimpleFileExFlags (fp=<value optimized out>, filename=0x7fffffffe232 "g19_framebuffer.py", 
    closeit=1, flags=0x7fffffffde30) at ../Python/pythonrun.c:941
#17 0x00000000004180c1 in Py_Main (argc=-135348096, argv=<value optimized out>) at ../Modules/main.c:577
#18 0x00007ffff69dad8e in __libc_start_main (main=<value optimized out>, argc=<value optimized out>, ubp_av=<value optimized out>, 
    init=<value optimized out>, fini=<value optimized out>, rtld_fini=<value optimized out>, stack_end=0x7fffffffdf48)
    at libc-start.c:226
#19 0x00000000004172c9 in _start ()


If it matters, I figured out I was trying to do what I was doing incorrectly. So I've found a better way to do it. 

The problem is specific to the bytearray() here, so it could very well be a problem with either bytearray or numpy.
msg128532 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-02-14 00:20
Judging from the traceback, you should probably report that issue to numpy instead.
History
Date User Action Args
2022-04-11 14:57:12adminsetgithub: 55416
2012-07-02 19:29:08brett.cannonsetstatus: pending -> closed
2011-02-14 00:20:07pitrousetstatus: open -> pending

nosy: + pitrou
messages: + msg128532

resolution: not a bug
2011-02-14 00:07:59David.Knappsetstatus: pending -> open

messages: + msg128531
2011-02-13 21:59:11brett.cannonsetstatus: open -> pending
nosy: + brett.cannon
messages: + msg128524

2011-02-13 21:56:02David.Knappcreate