Skip to content

Commit 36c6178

Browse files
authored
pythongh-126024: fix UBSan failure in unicodeobject.c:find_first_nonascii (pythonGH-127566)
1 parent 77a61c0 commit 36c6178

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Objects/unicodeobject.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5083,12 +5083,9 @@ find_first_nonascii(const unsigned char *start, const unsigned char *end)
50835083
const unsigned char *p2 = _Py_ALIGN_UP(p, SIZEOF_SIZE_T);
50845084
#if PY_LITTLE_ENDIAN && HAVE_CTZ
50855085
if (p < p2) {
5086-
#if defined(_M_AMD64) || defined(_M_IX86) || defined(__x86_64__) || defined(__i386__)
5087-
// x86 and amd64 are little endian and can load unaligned memory.
5088-
size_t u = *(const size_t*)p & ASCII_CHAR_MASK;
5089-
#else
5090-
size_t u = load_unaligned(p, p2 - p) & ASCII_CHAR_MASK;
5091-
#endif
5086+
size_t u;
5087+
memcpy(&u, p, sizeof(size_t));
5088+
u &= ASCII_CHAR_MASK;
50925089
if (u) {
50935090
return (ctz(u) - 7) / 8;
50945091
}

0 commit comments

Comments
 (0)