Author: Ronan Lamy <ronan.l...@gmail.com> Branch: py3.5 Changeset: r93022:57dc41aeb601 Date: 2017-11-14 21:14 +0000 http://bitbucket.org/pypy/pypy/changeset/57dc41aeb601/
Log: Check for NULL in PyMemoryView_FromBuffer diff --git a/pypy/module/cpyext/memoryobject.py b/pypy/module/cpyext/memoryobject.py --- a/pypy/module/cpyext/memoryobject.py +++ b/pypy/module/cpyext/memoryobject.py @@ -201,6 +201,10 @@ The memoryview object then owns the buffer represented by view, which means you shouldn't try to call PyBuffer_Release() yourself: it will be done on deallocation of the memoryview object.""" + if not view.c_buf: + raise oefmt(space.w_ValueError, + "PyMemoryView_FromBuffer(): info->buf must not be NULL") + # XXX this should allocate a PyMemoryViewObject and # copy view into obj.c_view, without creating a new view.c_obj typedescr = get_typedescr(W_MemoryView.typedef) diff --git a/pypy/module/cpyext/test/test_memoryobject.py b/pypy/module/cpyext/test/test_memoryobject.py --- a/pypy/module/cpyext/test/test_memoryobject.py +++ b/pypy/module/cpyext/test/test_memoryobject.py @@ -255,3 +255,13 @@ """)]) mv = module.new() assert mv.tobytes() == b'hell' + + def test_FromBuffer_NULL(self): + module = self.import_extension('foo', [ + ('new', 'METH_NOARGS', """ + Py_buffer info; + if (PyBuffer_FillInfo(&info, NULL, NULL, 1, 1, PyBUF_FULL_RO) < 0) + return NULL; + return PyMemoryView_FromBuffer(&info); + """)]) + raises(ValueError, module.new) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit