Skip to content

Commit 003db2f

Browse files
[3.13] gh-151284: Fix test_capi on UBSan (GH-151286) (#151325)
gh-151284: Fix test_capi on UBSan (GH-151286) Comment two checks relying on undefined behavior in test_fromwidechar() of test_capi. Enable test_capi in GitHub Action "Reusable Sanitizer". (cherry picked from commit d87d772) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent f1c8176 commit 003db2f

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Lib/test/test_capi/test_unicode.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,16 +796,18 @@ def test_fromwidechar(self):
796796
if SIZEOF_WCHAR_T == 2:
797797
self.assertEqual(fromwidechar('a\U0001f600'.encode(encoding), 2), 'a\ud83d')
798798

799-
self.assertRaises(MemoryError, fromwidechar, b'', PY_SSIZE_T_MAX)
800799
self.assertRaises(SystemError, fromwidechar, b'\0'*SIZEOF_WCHAR_T, -2)
801-
self.assertRaises(SystemError, fromwidechar, b'\0'*SIZEOF_WCHAR_T, PY_SSIZE_T_MIN)
802800
self.assertEqual(fromwidechar(NULL, 0), '')
803801
self.assertRaises(SystemError, fromwidechar, NULL, 1)
804802
self.assertRaises(SystemError, fromwidechar, NULL, PY_SSIZE_T_MAX)
805803
self.assertRaises(SystemError, fromwidechar, NULL, -1)
806804
self.assertRaises(SystemError, fromwidechar, NULL, -2)
807805
self.assertRaises(SystemError, fromwidechar, NULL, PY_SSIZE_T_MIN)
808806

807+
# The following tests are skipped since they rely on undefined behavior
808+
#self.assertRaises(MemoryError, fromwidechar, b'', PY_SSIZE_T_MAX)
809+
#self.assertRaises(SystemError, fromwidechar, b'\0'*SIZEOF_WCHAR_T, PY_SSIZE_T_MIN)
810+
809811
@support.cpython_only
810812
@unittest.skipIf(_testlimitedcapi is None, 'need _testlimitedcapi module')
811813
def test_aswidechar(self):

0 commit comments

Comments
 (0)