-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
_imp.get_frozen_object
possible incorrect use of PyBUF_READ
#114685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Other question, why it was not caught in tests? Does |
if (!REQ_FORMAT(flags)) {
/* NULL indicates that the buffer's data type has been cast to 'B'.
view->itemsize is the _previous_ itemsize. If shape is present,
the equality product(shape) * itemsize = len still holds at this
point. The equality calcsize(format) = itemsize does _not_ hold
from here on! */
view->format = NULL;
}
if (REQ_C_CONTIGUOUS(flags) && !MV_C_CONTIGUOUS(baseflags)) {
PyErr_SetString(PyExc_BufferError,
"memoryview: underlying buffer is not C-contiguous");
return -1;
}
if (REQ_F_CONTIGUOUS(flags) && !MV_F_CONTIGUOUS(baseflags)) {
PyErr_SetString(PyExc_BufferError,
"memoryview: underlying buffer is not Fortran contiguous");
return -1;
}
if (REQ_ANY_CONTIGUOUS(flags) && !MV_ANY_CONTIGUOUS(baseflags)) {
PyErr_SetString(PyExc_BufferError,
"memoryview: underlying buffer is not contiguous");
return -1;
}
|
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.
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.
Unfortunately the value of PyBUF_READ intersects with PyBUF_INDIRECT, PyBUF_FULL and PyBUF_FULL_RO, so we cannot just ban this bit. But fortunately other values has other bits set, so this error is still distinguishable. |
What about |
Maybe. We do not have examples of the misuse in this case, and it is much less used, but a similar error is possible here too. |
I will send an example PR, so we can decide 👍 |
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.
Bug report
It is documented that
PyBUF_READ
should be used withmemoryview
objects. But, it is used inPyObject_GetBuffer
:cpython/Python/import.c
Line 3547 in 5ecfd75
Other similar places that access
.buf
and.len
just usePyBUF_SIMPLE
, which I think we should use here as well.I will send a PR.
Originally found by @serhiy-storchaka in #114669 (comment)
Linked PRs
PyBUF_READ
inimport.c
#114686PyBuffer_FillInfo
now raises onPyBUF_{READ,WRITE}
#114802The text was updated successfully, but these errors were encountered: