]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-151284: Fix test_capi on UBSan (GH-151286) (#151325)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 11 Jun 2026 11:19:54 +0000 (13:19 +0200)
committerGitHub <noreply@github.com>
Thu, 11 Jun 2026 11:19:54 +0000 (11:19 +0000)
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 d87d77287392b78d36a06660228f6a5ca88888d7)

Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/test/test_capi/test_unicode.py

index f750ec1a56fef9da47a50791826aa118e6d14882..c9fa4fe31c76b90508d29a05099d5814310797a6 100644 (file)
@@ -796,9 +796,7 @@ class CAPITest(unittest.TestCase):
         if SIZEOF_WCHAR_T == 2:
             self.assertEqual(fromwidechar('a\U0001f600'.encode(encoding), 2), 'a\ud83d')
 
-        self.assertRaises(MemoryError, fromwidechar, b'', PY_SSIZE_T_MAX)
         self.assertRaises(SystemError, fromwidechar, b'\0'*SIZEOF_WCHAR_T, -2)
-        self.assertRaises(SystemError, fromwidechar, b'\0'*SIZEOF_WCHAR_T, PY_SSIZE_T_MIN)
         self.assertEqual(fromwidechar(NULL, 0), '')
         self.assertRaises(SystemError, fromwidechar, NULL, 1)
         self.assertRaises(SystemError, fromwidechar, NULL, PY_SSIZE_T_MAX)
@@ -806,6 +804,10 @@ class CAPITest(unittest.TestCase):
         self.assertRaises(SystemError, fromwidechar, NULL, -2)
         self.assertRaises(SystemError, fromwidechar, NULL, PY_SSIZE_T_MIN)
 
+        # The following tests are skipped since they rely on undefined behavior
+        #self.assertRaises(MemoryError, fromwidechar, b'', PY_SSIZE_T_MAX)
+        #self.assertRaises(SystemError, fromwidechar, b'\0'*SIZEOF_WCHAR_T, PY_SSIZE_T_MIN)
+
     @support.cpython_only
     @unittest.skipIf(_testlimitedcapi is None, 'need _testlimitedcapi module')
     def test_aswidechar(self):