gh-114685: PyBuffer_FillInfo() now raises on PyBUF_{READ,WRITE} (GH-114802)

This commit is contained in:
Nikita Sobolev 2024-02-04 22:16:43 +03:00 committed by GitHub
parent da8f9fb2ea
commit 929d44e15a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 56 additions and 5 deletions

View file

@ -767,11 +767,17 @@ PyBuffer_FillInfo(Py_buffer *view, PyObject *obj, void *buf, Py_ssize_t len,
return -1;
}
if (((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) &&
(readonly == 1)) {
PyErr_SetString(PyExc_BufferError,
"Object is not writable.");
return -1;
if (flags != PyBUF_SIMPLE) { /* fast path */
if (flags == PyBUF_READ || flags == PyBUF_WRITE) {
PyErr_BadInternalCall();
return -1;
}
if (((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) &&
(readonly == 1)) {
PyErr_SetString(PyExc_BufferError,
"Object is not writable.");
return -1;
}
}
view->obj = Py_XNewRef(obj);