Commit 566facd3 authored by Antoine Pitrou's avatar Antoine Pitrou

Merged revisions 88097 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r88097 | antoine.pitrou | 2011-01-18 19:57:52 +0100 (mar., 18 janv. 2011) | 4 lines

  Issue #10451: memoryview objects could allow to mutate a readable buffer.
  Initial patch by Ross Lagerwall.
........
parent cbb98950
...@@ -9,6 +9,7 @@ import sys ...@@ -9,6 +9,7 @@ import sys
import gc import gc
import weakref import weakref
import array import array
import io
class AbstractMemoryTests: class AbstractMemoryTests:
...@@ -225,6 +226,16 @@ class AbstractMemoryTests: ...@@ -225,6 +226,16 @@ class AbstractMemoryTests:
gc.collect() gc.collect()
self.assertTrue(wr() is None, wr()) 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 # Variations on source objects for the buffer: bytes-like objects, then arrays
# with itemsize > 1. # with itemsize > 1.
......
...@@ -10,6 +10,9 @@ What's New in Python 3.1.4? ...@@ -10,6 +10,9 @@ What's New in Python 3.1.4?
Core and Builtins 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 - Issue #10892: Don't segfault when trying to delete __abstractmethods__ from a
class. class.
......
...@@ -34,9 +34,6 @@ static int ...@@ -34,9 +34,6 @@ static int
memory_getbuf(PyMemoryViewObject *self, Py_buffer *view, int flags) memory_getbuf(PyMemoryViewObject *self, Py_buffer *view, int flags)
{ {
int res = 0; int res = 0;
/* XXX for whatever reason fixing the flags seems necessary */
if (self->view.readonly)
flags &= ~PyBUF_WRITABLE;
if (self->view.obj != NULL) if (self->view.obj != NULL)
res = PyObject_GetBuffer(self->view.obj, view, flags); res = PyObject_GetBuffer(self->view.obj, view, flags);
if (view) if (view)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment