Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a race condition in ``_PyBytes_FromList`` in free-threading mode.
7 changes: 5 additions & 2 deletions Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "pycore_global_objects.h"// _Py_GET_GLOBAL_OBJECT()
#include "pycore_initconfig.h" // _PyStatus_OK()
#include "pycore_long.h" // _PyLong_DigitValue
#include "pycore_list.h" // _PyList_GetItemRef
#include "pycore_object.h" // _PyObject_GC_TRACK
#include "pycore_pymem.h" // PYMEM_CLEANBYTE
#include "pycore_strhex.h" // _Py_strhex_with_sep()
Expand Down Expand Up @@ -2866,7 +2867,7 @@
Py_ssize_t i, size = PyList_GET_SIZE(x);
Py_ssize_t value;
char *str;
PyObject *item;

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04)

unused variable ‘item’ [-Wunused-variable]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04-arm)

unused variable ‘item’ [-Wunused-variable]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Cross build Linux

unused variable ‘item’ [-Wunused-variable]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu (bolt) / build and test (ubuntu-24.04)

unused variable ‘item’ [-Wunused-variable]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

unused variable ‘item’ [-Wunused-variable]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04-arm)

unused variable ‘item’ [-Wunused-variable]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

unused variable ‘item’ [-Wunused-variable]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

unused variable ‘item’ [-Wunused-variable]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (arm64)

'item': unreferenced local variable [C:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (arm64)

'item': unreferenced local variable [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (x64)

'item': unreferenced local variable [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (x64)

'item': unreferenced local variable [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'item': unreferenced local variable [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'item': unreferenced local variable [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'item': unreferenced local variable [C:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 2870 in Objects/bytesobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'item': unreferenced local variable [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]
_PyBytesWriter writer;

_PyBytesWriter_Init(&writer);
Expand All @@ -2877,8 +2878,10 @@
size = writer.allocated;

for (i = 0; i < PyList_GET_SIZE(x); i++) {
item = PyList_GET_ITEM(x, i);
Py_INCREF(item);
PyObject *item = _PyList_GetItemRef((PyListObject *)x, i);
if (item == NULL) {
goto error;
}
value = PyNumber_AsSsize_t(item, NULL);
Py_DECREF(item);
if (value == -1 && PyErr_Occurred())
Expand Down
Loading