Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
bast0006 wants to merge5 commits intopython:main
base:main
Choose a base branch
Loading
frombast0006:bast0006/gh-91153
Open
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
GH-91153: Handle _getbytevalue potentially invalidating bytearray all…
…ocation during item assignment
  • Loading branch information
@bast0006
bast0006 committedMar 29, 2025
commit71ae2125197bcc791c7d6e7b45c097dd4bd81618
7 changes: 5 additions & 2 deletionsObjects/bytearrayobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;
char *buf = PyByteArray_AS_STRING(self);
// GH-91153: we cannot store a reference to the internal buffer here, as _getbytevalue might call into python code
// that could then invalidate it.

if (_PyIndex_Check(index)) {
Py_ssize_t i = PyNumber_AsSsize_t(index, PyExc_IndexError);
Expand DownExpand Up@@ -744,7 +745,7 @@ bytearray_ass_subscript_lock_held(PyObject *op, PyObject *index, PyObject *value
}
else {
assert(0 <= ival && ival < 256);
buf[i] = (char)ival;
PyByteArray_AS_STRING(self)[i] = (char)ival;
return 0;
}
}
Expand DownExpand Up@@ -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);

if (!_canresize(self))
return -1;
Expand DownExpand Up@@ -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,
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp