Skip to content
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

memoview[0] creates an invalid view if ndim != 1 #52552

Closed
vstinner opened this issue Apr 3, 2010 · 8 comments
Closed

memoview[0] creates an invalid view if ndim != 1 #52552

vstinner opened this issue Apr 3, 2010 · 8 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@vstinner
Copy link
Member

vstinner commented Apr 3, 2010

BPO 8305
Nosy @gvanrossum, @birkenfeld, @mdickinson, @pitrou, @scoder, @vstinner, @benjaminp, @skrah
Superseder
  • bpo-10181: Problems with Py_buffer management in memoryobject.c (and elsewhere?)
  • Files
  • memoryview_crash.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2012-02-09.22:33:54.293>
    created_at = <Date 2010-04-03.15:24:41.446>
    labels = ['interpreter-core', 'type-crash']
    title = 'memoview[0] creates an invalid view if ndim != 1'
    updated_at = <Date 2012-03-02.07:49:15.344>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2012-03-02.07:49:15.344>
    actor = 'skrah'
    assignee = 'teoliphant'
    closed = True
    closed_date = <Date 2012-02-09.22:33:54.293>
    closer = 'skrah'
    components = ['Interpreter Core']
    creation = <Date 2010-04-03.15:24:41.446>
    creator = 'vstinner'
    dependencies = []
    files = ['16749']
    hgrepos = []
    issue_num = 8305
    keywords = []
    message_count = 8.0
    messages = ['102270', '102271', '102278', '103956', '141860', '152993', '154242', '154747']
    nosy_count = 10.0
    nosy_names = ['gvanrossum', 'georg.brandl', 'teoliphant', 'mark.dickinson', 'pitrou', 'scoder', 'vstinner', 'benjamin.peterson', 'skrah', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '10181'
    type = 'crash'
    url = 'https://bugs.python.org/issue8305'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2', 'Python 3.3']

    @vstinner
    Copy link
    Member Author

    vstinner commented Apr 3, 2010

    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.

    @vstinner
    Copy link
    Member Author

    vstinner commented Apr 3, 2010

    Full example (using numpy) crashing Python: memoryview_crash.py

    @vstinner vstinner added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Apr 3, 2010
    @vstinner
    Copy link
    Member Author

    vstinner commented Apr 3, 2010

    According to bpo-2394, the implementation of the new buffer API is not complete.

    @pitrou
    Copy link
    Member

    pitrou commented Apr 22, 2010

    I'll leave this to our numpy experts. I don't even know how to unit test this without installing numpy.

    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Aug 10, 2011

    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]

    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Feb 9, 2012

    Fixed in bpo-10181.

    @skrah skrah mannequin closed this as completed Feb 9, 2012
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 25, 2012

    New changeset 3f9b3b6f7ff0 by Stefan Krah in branch 'default':

    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Mar 2, 2012

    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 bpo-10181 won't be backported for a number of reasons, see:

    http://mail.python.org/pipermail/python-dev/2012-February/116872.html

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants