import weakref
import array
from test import test_support
+import io
class AbstractMemoryTests:
gc.collect()
self.assertTrue(wr() is None, wr())
+ def test_writable_readonly(self):
+ # Issue #10451: memoryview incorrectly exposes a readonly
+ # buffer as writable causing a segfault if using mmap
+ tp = self.ro_type
+ if tp is None:
+ return
+ b = tp(self._source)
+ m = self._view(b)
+ i = io.BytesIO(b'ZZZZ')
+ self.assertRaises(TypeError, i.readinto, m)
# Variations on source objects for the buffer: bytes-like objects, then arrays
# with itemsize > 1.
Core and Builtins
-----------------
+- Issue #10451: memoryview objects could allow to mutate a readable buffer.
+ Initial patch by Ross Lagerwall.
+
- Issue #10892: Don't segfault when trying to delete __abstractmethods__ from a
class.
memory_getbuf(PyMemoryViewObject *self, Py_buffer *view, int flags)
{
int res = 0;
- /* XXX for whatever reason fixing the flags seems necessary */
- if (self->view.readonly)
- flags &= ~PyBUF_WRITABLE;
if (self->view.obj != NULL)
res = PyObject_GetBuffer(self->view.obj, view, flags);
if (view)
Py_buffer view;
PyObject *res;
- if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_FULL) < 0)
+ if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_SIMPLE) < 0)
return NULL;
res = PyBytes_FromStringAndSize(NULL, view.len);