diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-11-11 01:59:42 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-11-11 01:59:42 (GMT) |
commit | 44c6affc796a84cb4b4e89eadd4c923958e9cc99 (patch) | |
tree | b567f792ed34793e6042f84f509aa41b08368c13 | |
parent | 9768676f6f1cc0c7b2efcf3258ef300c0417dbcb (diff) | |
download | cpython-44c6affc796a84cb4b4e89eadd4c923958e9cc99.zip cpython-44c6affc796a84cb4b4e89eadd4c923958e9cc99.tar.gz cpython-44c6affc796a84cb4b4e89eadd4c923958e9cc99.tar.bz2 |
Avoid crashing because of an unaligned word access
-rw-r--r-- | Objects/unicodeobject.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 772707d..a4d210b 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -6252,7 +6252,15 @@ _PyUnicode_DecodeUnicodeInternal(const char *s, end = s + size; while (s < end) { - Py_UCS4 ch = *(Py_UNICODE*)s; + Py_UCS4 ch; + /* We copy the raw representation one byte at a time because the + pointer may be unaligned (see test_codeccallbacks). */ + ((char *) &ch)[0] = s[0]; + ((char *) &ch)[1] = s[1]; +#ifdef Py_UNICODE_WIDE + ((char *) &ch)[2] = s[2]; + ((char *) &ch)[3] = s[3]; +#endif /* We have to sanity check the raw data, otherwise doom looms for some malformed UCS-4 data. */ if ( |