Skip to content

bytearray().__buffer__(256) crashes #126980

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

Closed
sobolevn opened this issue Nov 18, 2024 · 0 comments
Closed

bytearray().__buffer__(256) crashes #126980

sobolevn opened this issue Nov 18, 2024 · 0 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@sobolevn
Copy link
Member

sobolevn commented Nov 18, 2024

Crash report

Code says that it cannot fail:

static int
bytearray_getbuffer(PyObject *self, Py_buffer *view, int flags)
{
PyByteArrayObject *obj = _PyByteArray_CAST(self);
if (view == NULL) {
PyErr_SetString(PyExc_BufferError,
"bytearray_getbuffer: view==NULL argument is obsolete");
return -1;
}
void *ptr = (void *) PyByteArray_AS_STRING(obj);
/* cannot fail if view != NULL and readonly == 0 */
(void)PyBuffer_FillInfo(view, (PyObject*)obj, ptr, Py_SIZE(obj), 0, flags);

But, it can:

cpython/Objects/abstract.c

Lines 770 to 774 in 4cd1076

if (flags != PyBUF_SIMPLE) { /* fast path */
if (flags == PyBUF_READ || flags == PyBUF_WRITE) {
PyErr_BadInternalCall();
return -1;
}

I have a PR ready.

CC @JelleZijlstra

Linked PRs

@sobolevn sobolevn added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Nov 18, 2024
@sobolevn sobolevn self-assigned this Nov 18, 2024
sobolevn added a commit to sobolevn/cpython that referenced this issue Nov 18, 2024
sobolevn added a commit that referenced this issue Nov 19, 2024
sobolevn added a commit to sobolevn/cpython that referenced this issue Nov 19, 2024
…EAD,WRITE}` (pythonGH-126981)

(cherry picked from commit 3932e1d)

Co-authored-by: sobolevn <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
sobolevn added a commit to sobolevn/cpython that referenced this issue Nov 19, 2024
…EAD,WRITE}` (pythonGH-126981)

(cherry picked from commit 3932e1d)

Co-authored-by: sobolevn <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
sobolevn added a commit that referenced this issue Nov 19, 2024
…ITE}` (GH-126981) (#127023)

(cherry picked from commit 3932e1d)

Co-authored-by: Victor Stinner <[email protected]>
ebonnal pushed a commit to ebonnal/cpython that referenced this issue Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

1 participant