Skip to content

Commit 5854cf3

Browse files
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 <[email protected]>
1 parent 6b4e3fe commit 5854cf3

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
@@ -457,7 +457,9 @@ _locale_strxfrm_impl(PyObject *module, PyObject *str)
457457

458458
/* assume no change in size, first */
459459
n1 = n1 + 1;
460-
buf = PyMem_New(wchar_t, n1);
460+
/* Yet another +1 is needed to work around a platform bug in wcsxfrm()
461+
* on macOS. See gh-130567. */
462+
buf = PyMem_New(wchar_t, n1+1);
461463
if (!buf) {
462464
PyErr_NoMemory();
463465
goto exit;

0 commit comments

Comments
 (0)