classification
Title: memoview[0] creates an invalid view if ndim != 1
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.1, Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Problems with Py_buffer management in memoryobject.c (and elsewhere?)
View: 10181
Assigned To: teoliphant Nosy List: benjamin.peterson, georg.brandl, gvanrossum, mark.dickinson, pitrou, python-dev, scoder, skrah, teoliphant, vstinner
Priority: normal Keywords:

Created on 2010-04-03 15:24 by vstinner, last changed 2012-03-02 07:49 by skrah. This issue is now closed.

Files
File name Uploaded Description Edit
memoryview_crash.py vstinner, 2010-04-03 15:25
Messages (8)
msg102270 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-04-03 15:24
memory_item() function creates a new memoryview object if ndim is different than 1. Example with numpy:

   from numpy import array
   y=array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])
   y.shape = 3,4
   view=memoryview(y)
   view2 = view[0]
   print type(view2)

Result: <type 'memoryview'>. (Without the shape, ndim equals 1, and view2 is a standard str object.)

The problem is that view attribute of the view2 (PyMemoryViewObject) is not initialized. Extract of memory_item():

        /* Return a new memory-view object */
        Py_buffer newview;
        memset(&newview, 0, sizeof(newview));
        /* XXX:  This needs to be fixed so it actually returns a sub-view */
        return PyMemoryView_FromBuffer(&newview);

"This needs to be fixed" :-/

--

view2 is not initialized and so view2.tolist() does crash.
msg102271 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-04-03 15:25
Full example (using numpy) crashing Python: memoryview_crash.py
msg102278 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-04-03 15:44
According to #2394, the implementation of the new buffer API is not complete.
msg103956 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-04-22 11:39
I'll leave this to our numpy experts. I don't even know how to unit test this without installing numpy.
msg141860 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2011-08-10 12:39
The crash is fixed in the features/pep-3118 repo:

>>> from numpy import array
>>> y=array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])
>>> y.shape = 3,4
>>> view=memoryview(y)
>>> view2 = view[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NotImplementedError: multi-dimensional sub-views are not implemented
[182251 refs]
msg152993 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2012-02-09 22:33
Fixed in #10181.
msg154242 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-02-25 11:25
New changeset 3f9b3b6f7ff0 by Stefan Krah in branch 'default':
- Issue #10181: New memoryview implementation fixes multiple ownership
http://hg.python.org/cpython/rev/3f9b3b6f7ff0
msg154747 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2012-03-02 07:49
Since this issue targeted 2.7 and 3.2:

In a brief discussion on python-dev it was decided that the 3.3 fixes
from #10181 won't be backported for a number of reasons, see:

http://mail.python.org/pipermail/python-dev/2012-February/116872.html
History
Date User Action Args
2012-03-02 07:49:15skrahsetmessages: + msg154747
2012-02-25 11:25:31python-devsetnosy: + python-dev
messages: + msg154242
2012-02-09 22:33:54skrahsetstatus: open -> closed
superseder: Problems with Py_buffer management in memoryobject.c (and elsewhere?)
messages: + msg152993

dependencies: - Problems with Py_buffer management in memoryobject.c (and elsewhere?)
resolution: duplicate
stage: needs patch -> resolved
2011-08-10 12:39:21skrahsetnosy: + skrah
dependencies: + Problems with Py_buffer management in memoryobject.c (and elsewhere?)
messages: + msg141860
2011-05-09 15:29:40pitrousetnosy: + mark.dickinson

versions: + Python 3.3
2010-04-22 11:39:08pitrousetpriority: normal
assignee: teoliphant
messages: + msg103956

stage: needs patch
2010-04-22 11:31:59vstinnersetnosy: + gvanrossum, georg.brandl, pitrou, scoder, benjamin.peterson
2010-04-03 15:44:56vstinnersetnosy: + teoliphant
messages: + msg102278
2010-04-03 15:26:35vstinnersettype: crash
components: + Interpreter Core
2010-04-03 15:25:56vstinnersetfiles: + memoryview_crash.py

messages: + msg102271
2010-04-03 15:24:41vstinnercreate