[FFmpeg-devel] [PATCH] Fix av_crc unaligned accesses

Jeff Downs heydowns
Fri Jun 12 00:48:25 CEST 2009


Currently, av_crc() blindly casts a byte buffer to uint32 without regard 
for alignment requirements.  The documentation doesn't state any alignment 
requirements.

This issue causes crashes during decoding on sparc.

Attached changes the implementation to compute byte-by-byte until aligned, 
then proceeds with the 32-bit-based calculations.

Alternatively, docs could be added to specify alignment restriction. (I 
know of at least one decoder that would need to be changed to meet such a
requirement)

	-Jeff
-------------- next part --------------
Index: libavutil/crc.c
===================================================================
--- libavutil/crc.c	(revision 19144)
+++ libavutil/crc.c	(working copy)
@@ -115,7 +115,10 @@
     const uint8_t *end= buffer+length;
 
 #if !CONFIG_SMALL
-    if(!ctx[256])
+    if(!ctx[256]) {
+        while(((intptr_t) buffer & 3) && buffer < end)
+            crc = ctx[((uint8_t)crc) ^ *buffer++] ^ (crc >> 8);
+
         while(buffer<end-3){
             crc ^= le2me_32(*(const uint32_t*)buffer); buffer+=4;
             crc =  ctx[3*256 + ( crc     &0xFF)]
@@ -123,6 +126,7 @@
                   ^ctx[1*256 + ((crc>>16)&0xFF)]
                   ^ctx[0*256 + ((crc>>24)     )];
         }
+    }
 #endif
     while(buffer<end)
         crc = ctx[((uint8_t)crc) ^ *buffer++] ^ (crc >> 8);



More information about the ffmpeg-devel mailing list