Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.3k
gh-91153: Fix bytearray holding a reference to its internal buffer when calling into potentially mutating __index__ methods#132379
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
71ae212
b2f7df5
bb96c2a
d29422b
d3d1974
18e6597
4b7ec9c
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
…ocation during item assignment
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -709,7 +709,8 @@ bytearray_ass_subscript_lock_held(PyObject *op, PyObject *index, PyObject *value | ||
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op); | ||
PyByteArrayObject *self = _PyByteArray_CAST(op); | ||
Py_ssize_t start, stop, step, slicelen; | ||
// GH-91153: we cannot store a reference to the internal buffer here, as _getbytevalue might call into python code | ||
// that could then invalidate it. | ||
bast0006 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if (_PyIndex_Check(index)) { | ||
Py_ssize_t i = PyNumber_AsSsize_t(index, PyExc_IndexError); | ||
@@ -744,7 +745,7 @@ bytearray_ass_subscript_lock_held(PyObject *op, PyObject *index, PyObject *value | ||
} | ||
else { | ||
assert(0 <= ival && ival < 256); | ||
PyByteArray_AS_STRING(self)[i] = (char)ival; | ||
return 0; | ||
} | ||
} | ||
@@ -805,6 +806,7 @@ bytearray_ass_subscript_lock_held(PyObject *op, PyObject *index, PyObject *value | ||
/* Delete slice */ | ||
size_t cur; | ||
Py_ssize_t i; | ||
char* buf = PyByteArray_AS_STRING(self); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. We can also hold There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I agree, but I'm not as familiar with this system or C as I would want to be to feel comfortable making that change. Especially since the relevant code is mostly >10 years old and that change is not immediately required to solve the issue. | ||
if (!_canresize(self)) | ||
return -1; | ||
@@ -845,6 +847,7 @@ bytearray_ass_subscript_lock_held(PyObject *op, PyObject *index, PyObject *value | ||
/* Assign slice */ | ||
Py_ssize_t i; | ||
size_t cur; | ||
char* buf = PyByteArray_AS_STRING(self); | ||
if (needed != slicelen) { | ||
PyErr_Format(PyExc_ValueError, | ||