[3.14] gh-130567: Fix possible crash in locale.strxfrm() (GH-138940) (GH-139265)

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.

(cherry picked from commit 5854cf38a2)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-10-07 21:54:04 +02:00 committed by GitHub
parent d912e9a852
commit fff26500e5
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;