]> git.sesse.net Git - ffmpeg/commitdiff
cook: expand dither_tab[], and make sure indexes into it don't overflow.
authorRonald S. Bultje <rsbultje@gmail.com>
Fri, 9 Mar 2012 01:09:27 +0000 (17:09 -0800)
committerRonald S. Bultje <rsbultje@gmail.com>
Sat, 10 Mar 2012 20:03:53 +0000 (12:03 -0800)
Fixes overflows in accessing dither_tab[].

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
libavcodec/cook.c
libavcodec/cookdata.h

index 65e16e40773337b173fd59f5b986e20d937ed7bc..41ce0e528e428f00b96991a23e32e0a31f24f172 100644 (file)
@@ -507,7 +507,11 @@ static inline void expand_category(COOKContext *q, int *category,
 {
     int i;
     for (i = 0; i < q->num_vectors; i++)
-        ++category[category_index[i]];
+    {
+        int idx = category_index[i];
+        if (++category[idx] >= FF_ARRAY_ELEMS(dither_tab))
+            --category[idx];
+    }
 }
 
 /**
index 126010a985ac7fdc851a873be9aff9053ad99969..c4c26fae5f8b455c6aa1a9087bcdf8d6c6a0200d 100644 (file)
@@ -36,8 +36,8 @@ static const int expbits_tab[8] = {
     52,47,43,37,29,22,16,0,
 };
 
-static const float dither_tab[8] = {
-  0.0, 0.0, 0.0, 0.0, 0.0, 0.176777, 0.25, 0.707107,
+static const float dither_tab[9] = {
+  0.0, 0.0, 0.0, 0.0, 0.0, 0.176777, 0.25, 0.707107, 1.0
 };
 
 static const float quant_centroid_tab[7][14] = {