gh-130567: Fix possible crash in locale.strxfrm() (GH-138940)

On some macOS versions there was an off-by-one error in wcsxfrm() which
caused writing past the end of the array if its size was not calculated
by running wcsxfrm() first.

Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
This commit is contained in:
Serhiy Storchaka 2025-09-23 18:11:50 +03:00 committed by GitHub
parent 6b4e3fe9d4
commit 5854cf38a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View file

@ -0,0 +1,2 @@
Fix possible crash in :func:`locale.strxfrm` due to a platform bug on
macOS.

View file

@ -457,7 +457,9 @@ _locale_strxfrm_impl(PyObject *module, PyObject *str)
/* assume no change in size, first */
n1 = n1 + 1;
buf = PyMem_New(wchar_t, n1);
/* Yet another +1 is needed to work around a platform bug in wcsxfrm()
* on macOS. See gh-130567. */
buf = PyMem_New(wchar_t, n1+1);
if (!buf) {
PyErr_NoMemory();
goto exit;