[New-bugs-announce] [issue2692] bytes object wrongly exposes writeable buffer interface

Thomas Heller report at bugs.python.org
Fri Apr 25 19:14:49 CEST 2008

New submission from Thomas Heller <theller at ctypes.org>:

IIUC, the bytes object should be immutable (in contrast to bytearray). 
But PyObject_FromWriteBuffer() does not fail.

It seems that the attached patch fixes it; however there are lots of
failures in the testsuite with the patch - even 'memoryview(b"abcd")' fails.

Index: stringobject.c
--- stringobject.c	(revision 62498)
+++ stringobject.c	(working copy)
@@ -966,7 +966,7 @@
 string_buffer_getbuffer(PyStringObject *self, Py_buffer *view, int flags)
 	return PyBuffer_FillInfo(view, (void *)self->ob_sval, Py_SIZE(self),
-				 0, flags);
+				 1, flags);
 static PySequenceMethods string_as_sequence = {

components: Interpreter Core
messages: 65796
nosy: theller
severity: normal
status: open
title: bytes object wrongly exposes writeable buffer interface
versions: Python 3.0

Tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list