avcodec/utvideodec: Fix undefined behavior in shift
authorMichael Niedermayer <michaelni@gmx.at>
Tue, 11 Nov 2014 02:34:58 +0000 (03:34 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Tue, 11 Nov 2014 02:35:57 +0000 (03:35 +0100)
Fixes: asan_heap-oob_2573085_3783_utvideo_rgba_median.avi
Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/utvideodec.c

index 05c943f808c986d763ab94eb368d67b6d0c73edc..b565c1076c6a82a18ad1268f8ef08e5c8684b0cd 100644 (file)
@@ -56,13 +56,14 @@ static int build_huff(const uint8_t *src, VLC *vlc, int *fsym)
         *fsym = he[0].sym;
         return 0;
     }
-    if (he[0].len > 32)
-        return -1;
 
     last = 255;
     while (he[last].len == 255 && last)
         last--;
 
+    if (he[last].len > 32)
+        return -1;
+
     code = 1;
     for (i = last; i >= 0; i--) {
         codes[i] = code >> (32 - he[i].len);