Skip to content

gh-148286: Run test_capi and test_faulthandler on GHA UBSan - #151274

Closed
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:ubsan
Closed

vstinner wants to merge 1 commit into
python:mainfrom
vstinner:ubsan

Conversation

@vstinner

@vstinner vstinner commented Jun 10, 2026 •

Copy link
Copy Markdown
Member
@vstinner

Copy link
Copy Markdown
Member Author

These 2 tests have been skipped by commit ade914b (PR gh-148168).

@vstinner

Copy link
Copy Markdown
Member Author

I cannot reproduce test_capi or test_faulthandler failure locally. I built Python with ./configure --with-pydebug --with-undefined-behavior-sanitizer CC=clang LD=clang:

$ UBSAN_OPTIONS='halt_on_error=1' ./python -m test -j0 test_capi test_faulthandler 
...
0:00:16 load avg: 0.69 mem: 61.4 MiB [1/2] test_faulthandler passed
0:00:23 load avg: 0.90 mem: 34.7 MiB [2/2] test_capi passed
...
All 2 tests OK.
...
@vstinner

Copy link
Copy Markdown
Member Author

Ah, the "Sanitizers / UBSan" CI failed:

  • 1 test failed: test_capi
  • The "Display logs" step contains many errors related to faulthandler
@vstinner

Copy link
Copy Markdown
Member Author

I rebuilt Python with CC=clang ./configure --config-cache --with-undefined-behavior-sanitizer --with-strict-overflow --with-pydebug && make clean && make.

Aha. This time I'm able to reproduce the error:

$ UBSAN_OPTIONS="halt_on_error=1" ./python -m test -v test_capi -m test_fromwidechar
test_fromwidechar (test.test_capi.test_unicode.CAPITest.test_fromwidechar)
Test PyUnicode_FromWideChar() ...

Objects/unicodeobject.c:1942:38: runtime error: addition of unsigned offset to 0x0000017b51d8 overflowed to 0x0000017b51d4
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/unicodeobject.c:1942:38 
@vstinner

Copy link
Copy Markdown
Member Author

test_capi pass with this change:

diff --git a/Lib/test/test_capi/test_unicode.py b/Lib/test/test_capi/test_unicode.py
index 5dee25756fe..16ee04ba22b 100644
--- a/Lib/test/test_capi/test_unicode.py
+++ b/Lib/test/test_capi/test_unicode.py
@@ -842,9 +842,9 @@ def test_fromwidechar(self):
         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(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.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)
@vstinner

Copy link
Copy Markdown
Member Author

I created #151278 to fix test_faulthandler. Once test_faulthandler will be fixed, I will create an issue to fix test_capi.

I close this PR since it's wrong. We cannot just reenable the tests since they fail.

@vstinner vstinner closed this Jun 10, 2026
@vstinner
vstinner deleted the ubsan branch July 10, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant