[Python-checkins] r88097 - in python/branches/py3k: Lib/test/test_getargs2.py Lib/test/test_memoryview.py Misc/NEWS Objects/memoryobject.c

antoine.pitrou python-checkins at python.org
Tue Jan 18 19:57:52 CET 2011


Author: antoine.pitrou
Date: Tue Jan 18 19:57:52 2011
New Revision: 88097
Log:
Issue #10451: memoryview objects could allow to mutate a readable buffer.
Initial patch by Ross Lagerwall.
Modified:
 python/branches/py3k/Lib/test/test_getargs2.py
 python/branches/py3k/Lib/test/test_memoryview.py
 python/branches/py3k/Misc/NEWS
 python/branches/py3k/Objects/memoryobject.c
Modified: python/branches/py3k/Lib/test/test_getargs2.py
==============================================================================
--- python/branches/py3k/Lib/test/test_getargs2.py	(original)
+++ python/branches/py3k/Lib/test/test_getargs2.py	Tue Jan 18 19:57:52 2011
@@ -381,8 +381,10 @@
 self.assertRaises(TypeError, getargs_w_star, 'abc\xe9')
 self.assertRaises(TypeError, getargs_w_star, b'bytes')
 self.assertRaises(TypeError, getargs_w_star, b'nul:0円')
+ self.assertRaises(TypeError, getargs_w_star, memoryview(b'bytes'))
 self.assertEqual(getargs_w_star(bytearray(b'bytearray')), b'[ytearra]')
- self.assertEqual(getargs_w_star(memoryview(b'memoryview')), b'[emoryvie]')
+ self.assertEqual(getargs_w_star(memoryview(bytearray(b'memoryview'))),
+ b'[emoryvie]')
 self.assertRaises(TypeError, getargs_w_star, None)
 
 
Modified: python/branches/py3k/Lib/test/test_memoryview.py
==============================================================================
--- python/branches/py3k/Lib/test/test_memoryview.py	(original)
+++ python/branches/py3k/Lib/test/test_memoryview.py	Tue Jan 18 19:57:52 2011
@@ -9,6 +9,7 @@
 import gc
 import weakref
 import array
+import io
 
 
 class AbstractMemoryTests:
@@ -271,6 +272,17 @@
 m.release()
 self._check_released(m, tp)
 
+ 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.
 # NOTE: support for multi-dimensional objects is unimplemented.
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Tue Jan 18 19:57:52 2011
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #10451: memoryview objects could allow to mutate a readable buffer.
+ Initial patch by Ross Lagerwall.
+
 Library
 -------
 
Modified: python/branches/py3k/Objects/memoryobject.c
==============================================================================
--- python/branches/py3k/Objects/memoryobject.c	(original)
+++ python/branches/py3k/Objects/memoryobject.c	Tue Jan 18 19:57:52 2011
@@ -52,9 +52,6 @@
 {
 int res = 0;
 CHECK_RELEASED_INT(self);
- /* 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)


More information about the Python-checkins mailing list

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