[Python-checkins] r88099 - in python/branches/release27-maint: Lib/test/test_memoryview.py Misc/NEWS Objects/memoryobject.c

antoine.pitrou python-checkins at python.org
Tue Jan 18 20:06:25 CET 2011


Author: antoine.pitrou
Date: Tue Jan 18 20:06:19 2011
New Revision: 88099
Log:
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.
........
Modified:
 python/branches/release27-maint/ (props changed)
 python/branches/release27-maint/Lib/test/test_memoryview.py
 python/branches/release27-maint/Misc/NEWS
 python/branches/release27-maint/Objects/memoryobject.c
Modified: python/branches/release27-maint/Lib/test/test_memoryview.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_memoryview.py	(original)
+++ python/branches/release27-maint/Lib/test/test_memoryview.py	Tue Jan 18 20:06:19 2011
@@ -9,6 +9,7 @@
 import weakref
 import array
 from test import test_support
+import io
 
 
 class AbstractMemoryTests:
@@ -230,6 +231,16 @@
 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.
Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS	(original)
+++ python/branches/release27-maint/Misc/NEWS	Tue Jan 18 20:06:19 2011
@@ -9,6 +9,9 @@
 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.
 
Modified: python/branches/release27-maint/Objects/memoryobject.c
==============================================================================
--- python/branches/release27-maint/Objects/memoryobject.c	(original)
+++ python/branches/release27-maint/Objects/memoryobject.c	Tue Jan 18 20:06:19 2011
@@ -34,9 +34,6 @@
 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)
@@ -411,7 +408,7 @@
 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);


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /