Skip to content

Commit d1f6b39

Browse files
miss-islingtonserhiy-storchakaronaldoussoren
authored
[3.13] gh-130567: Fix possible crash in locale.strxfrm() (GH-138940) (GH-139266)
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 5854cf3) Co-authored-by: Serhiy Storchaka <[email protected]> Co-authored-by: Ronald Oussoren <[email protected]>
1 parent 7f83461 commit d1f6b39

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix possible crash in :func:`locale.strxfrm` due to a platform bug on
2+
macOS.

Modules/_localemodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,9 @@ _locale_strxfrm_impl(PyObject *module, PyObject *str)
446446

447447
/* assume no change in size, first */
448448
n1 = n1 + 1;
449-
buf = PyMem_New(wchar_t, n1);
449+
/* Yet another +1 is needed to work around a platform bug in wcsxfrm()
450+
* on macOS. See gh-130567. */
451+
buf = PyMem_New(wchar_t, n1+1);
450452
if (!buf) {
451453
PyErr_NoMemory();
452454
goto exit;

0 commit comments

Comments
 (0)