]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-130567: Fix possible crash in locale.strxfrm() (GH-138940)
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 23 Sep 2025 15:11:50 +0000 (18:11 +0300)
committerGitHub <noreply@github.com>
Tue, 23 Sep 2025 15:11:50 +0000 (15:11 +0000)
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>
Misc/NEWS.d/next/Library/2025-09-15-19-29-12.gh-issue-130567.shDEnT.rst [new file with mode: 0644]
Modules/_localemodule.c

diff --git a/Misc/NEWS.d/next/Library/2025-09-15-19-29-12.gh-issue-130567.shDEnT.rst b/Misc/NEWS.d/next/Library/2025-09-15-19-29-12.gh-issue-130567.shDEnT.rst
new file mode 100644 (file)
index 0000000..c194b23
--- /dev/null
@@ -0,0 +1,2 @@
+Fix possible crash in :func:`locale.strxfrm` due to a platform bug on
+macOS.
index e86d5b17d1759d6c42042c7ee19e939b0018c496..cb448b14d8cd63206029e638bcf6dd7c6c2ad262 100644 (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;