[Python-checkins] cpython: Avoid crashing because of an unaligned word access

antoine.pitrou python-checkins at python.org
Fri Nov 11 03:09:10 CET 2011


http://hg.python.org/cpython/rev/82c29c65435e
changeset:   73489:82c29c65435e
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Fri Nov 11 02:59:42 2011 +0100
summary:
  Avoid crashing because of an unaligned word access

files:
  Objects/unicodeobject.c |  10 +++++++++-
  1 files changed, 9 insertions(+), 1 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -6252,7 +6252,15 @@
     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 (

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list