diff -r eaac55703796 Modules/_testbuffer.c --- a/Modules/_testbuffer.c Wed Aug 22 17:45:52 2012 +0200 +++ b/Modules/_testbuffer.c Thu Aug 23 10:03:59 2012 +0200 @@ -2362,6 +2362,11 @@ get_ascii_order(PyObject *order) ord = PyBytes_AS_STRING(ascii_order)[0]; Py_DECREF(ascii_order); + + if (ord != 'C' && ord != 'F' && ord != 'A') { + PyErr_Format(PyExc_ValueError, "invalid order, must be C, F or A, got %c", order) + return CHAR_MAX; + } return ord; } @@ -2388,12 +2393,15 @@ get_contiguous(PyObject *self, PyObject if (type == -1 && PyErr_Occurred()) { return NULL; } - - ord = get_ascii_order(order); - if (ord == CHAR_MAX) { + if (buffertype != PyBUF_READ && buffertype != PyBUF_WRITE) { + PyErr_SetString(PyExc_ValueError, "invalid buffer type"); return NULL; } + ord = get_ascii_order(order); + if (ord == CHAR_MAX) + return NULL; + return PyMemoryView_GetContiguous(obj, (int)type, ord); }