Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 44c6aff

Browse files
committed
Avoid crashing because of an unaligned word access
1 parent 9768676 commit 44c6aff

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Objects/unicodeobject.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6252,7 +6252,15 @@ _PyUnicode_DecodeUnicodeInternal(const char *s,
62526252
end = s + size;
62536253

62546254
while (s < end) {
6255-
Py_UCS4 ch = *(Py_UNICODE*)s;
6255+
Py_UCS4 ch;
6256+
/* We copy the raw representation one byte at a time because the
6257+
pointer may be unaligned (see test_codeccallbacks). */
6258+
((char *) &ch)[0] = s[0];
6259+
((char *) &ch)[1] = s[1];
6260+
#ifdef Py_UNICODE_WIDE
6261+
((char *) &ch)[2] = s[2];
6262+
((char *) &ch)[3] = s[3];
6263+
#endif
62566264
/* We have to sanity check the raw data, otherwise doom looms for
62576265
some malformed UCS-4 data. */
62586266
if (

0 commit comments

Comments
 (0)