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-144128: Fix crash in array.fromlist with reentrant __index__#144138

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

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
10 commits
Select commitHold shift + click to select a range
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
17 changes: 17 additions & 0 deletionsLib/test/test_array.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -67,6 +67,23 @@ def test_empty(self):
a += a
self.assertEqual(len(a), 0)

def test_fromlist_reentrant_index_mutation(self):

class Evil:
def __init__(self, lst):
self.lst = lst
def __index__(self):
self.lst.clear()
return "not an int"

for typecode in ('I', 'L', 'Q'):
with self.subTest(typecode=typecode):
lst = []
lst.append(Evil(lst))
a = array.array(typecode)
with self.assertRaises(TypeError):
a.fromlist(lst)


# Machine format codes.
#
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Fix a crash in :meth:`array.array.fromlist` when an element's :meth:`~object.__index__` method mutates
the input list during conversion.
21 changes: 15 additions & 6 deletionsModules/arraymodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -408,10 +408,13 @@ II_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
int do_decref = 0; /* if nb_int was called */

if (!PyLong_Check(v)) {
v = _PyNumber_Index(v);
if (NULL == v) {
Py_INCREF(v);
PyObject *res = _PyNumber_Index(v);
Py_DECREF(v);
if (NULL == res) {
return -1;
}
v = res;
do_decref = 1;
}
x = PyLong_AsUnsignedLong(v);
Expand DownExpand Up@@ -468,10 +471,13 @@ LL_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
int do_decref = 0; /* if nb_int was called */

if (!PyLong_Check(v)) {
v = _PyNumber_Index(v);
if (NULL == v) {
Py_INCREF(v);
PyObject *res = _PyNumber_Index(v);
Py_DECREF(v);
if (NULL == res) {
return -1;
}
v = res;
do_decref = 1;
}
x = PyLong_AsUnsignedLong(v);
Expand DownExpand Up@@ -521,10 +527,13 @@ QQ_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
int do_decref = 0; /* if nb_int was called */

if (!PyLong_Check(v)) {
v = _PyNumber_Index(v);
if (NULL == v) {
Py_INCREF(v);
PyObject *res = _PyNumber_Index(v);
Py_DECREF(v);
if (NULL == res) {
return -1;
}
v = res;
do_decref = 1;
}
x = PyLong_AsUnsignedLongLong(v);
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp