Browse code

asfcrypt: fix unaligned accesses with armcc

Compilers may assume a pointer has natural alignment, even if it was
assigned from a pointer type with weaker alignment requirements. It
is thus not safe to assign a possibly unaligned value to a pointer,
regardless of how it is subsequently dereferenced.

Originally committed as revision 24897 to svn://svn.ffmpeg.org/ffmpeg/trunk

Måns Rullgård authored on 2010/08/24 22:42:28
Showing 1 changed files
... ...
@@ -139,7 +139,7 @@ void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len) {
139 139
     struct AVDES des;
140 140
     struct AVRC4 rc4;
141 141
     int num_qwords = len >> 3;
142
-    uint64_t *qwords = (uint64_t *)data;
142
+    uint8_t *qwords = data;
143 143
     uint64_t rc4buff[8];
144 144
     uint64_t packetkey;
145 145
     uint32_t ms_keys[12];
... ...
@@ -156,7 +156,7 @@ void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len) {
156 156
     av_rc4_crypt(&rc4, (uint8_t *)rc4buff, NULL, sizeof(rc4buff), NULL, 1);
157 157
     multiswap_init((uint8_t *)rc4buff, ms_keys);
158 158
 
159
-    packetkey = AV_RN64(&qwords[num_qwords - 1]);
159
+    packetkey = AV_RN64(&qwords[num_qwords*8 - 8]);
160 160
     packetkey ^= rc4buff[7];
161 161
     av_des_init(&des, key + 12, 64, 1);
162 162
     av_des_crypt(&des, (uint8_t *)&packetkey, (uint8_t *)&packetkey, 1, NULL, 1);
... ...
@@ -166,7 +166,7 @@ void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len) {
166 166
     av_rc4_crypt(&rc4, data, data, len, NULL, 1);
167 167
 
168 168
     ms_state = 0;
169
-    for (i = 0; i < num_qwords - 1; i++, qwords++)
169
+    for (i = 0; i < num_qwords - 1; i++, qwords += 8)
170 170
         ms_state = multiswap_enc(ms_keys, ms_state, AV_RL64(qwords));
171 171
     multiswap_invert_keys(ms_keys);
172 172
     packetkey = (packetkey << 32) | (packetkey >> 32);