gh-114685: Check flags in PyObject_GetBuffer() (GH-114707)

PyObject_GetBuffer() now raises a SystemError if called with
PyBUF_READ or PyBUF_WRITE as flags. These flags should
only be used with the PyMemoryView_* C API.
This commit is contained in:
Serhiy Storchaka 2024-01-31 13:11:35 +02:00 • committed by GitHub
parent 7a93db4425
commit b7688ef71e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 2 deletions

View file

@ -54,8 +54,10 @@ static int
testbuf_getbuf(testBufObject *self, Py_buffer *view, int flags)
{
int buf = PyObject_GetBuffer(self->obj, view, flags);
Py_SETREF(view->obj, Py_NewRef(self));
self->references++;
if (buf == 0) {
Py_SETREF(view->obj, Py_NewRef(self));
self->references++;
}
return buf;
}