Skip to content

Commit 5ddaeff

Browse files
gh-130567: Fix crash in locale.strxfrm() on macOS
1 parent 4ed046c commit 5ddaeff

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Lib/test/test_locale.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,7 @@ def setUp(self):
351351
enc = codecs.lookup(locale.getencoding() or 'ascii').name
352352
if enc not in ('utf-8', 'iso8859-1', 'cp1252'):
353353
raise unittest.SkipTest('encoding not suitable')
354-
if enc != 'iso8859-1' and (sys.platform == 'darwin' or is_android or
355-
sys.platform.startswith('freebsd')):
354+
if enc != 'iso8859-1' and is_android:
356355
raise unittest.SkipTest('wcscoll/wcsxfrm have known bugs')
357356
BaseLocalizedTest.setUp(self)
358357

@@ -372,6 +371,16 @@ def test_strcoll_with_diacritic(self):
372371
def test_strxfrm_with_diacritic(self):
373372
self.assertLess(locale.strxfrm('à'), locale.strxfrm('b'))
374373

374+
def test_xxx(self):
375+
bad = []
376+
for c in map(chr, range(1, 0x3000)):
377+
if c.isprintable():
378+
s = locale.strxfrm(c)
379+
if '\1' in s:
380+
bad += c
381+
print(f'{c!r} {c!a} -> {s!a}')
382+
self.fail(repr(''.join(bad)))
383+
375384

376385
class NormalizeTest(unittest.TestCase):
377386
def check(self, localename, expected):

Modules/_localemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ _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+
buf = PyMem_New(wchar_t, n1+1);
461461
if (!buf) {
462462
PyErr_NoMemory();
463463
goto exit;

0 commit comments

Comments
 (0)