Commit 442c3a8c authored by Ronald S. Bultje's avatar Ronald S. Bultje

cook: expand dither_tab[], and make sure indexes into it don't overflow.

Fixes overflows in accessing dither_tab[].

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
parent 71af42bd
...@@ -507,7 +507,11 @@ static inline void expand_category(COOKContext *q, int *category, ...@@ -507,7 +507,11 @@ static inline void expand_category(COOKContext *q, int *category,
{ {
int i; int i;
for (i = 0; i < q->num_vectors; 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];
}
} }
/** /**
......
...@@ -36,8 +36,8 @@ static const int expbits_tab[8] = { ...@@ -36,8 +36,8 @@ static const int expbits_tab[8] = {
52,47,43,37,29,22,16,0, 52,47,43,37,29,22,16,0,
}; };
static const float dither_tab[8] = { static const float dither_tab[9] = {
0.0, 0.0, 0.0, 0.0, 0.0, 0.176777, 0.25, 0.707107, 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] = { static const float quant_centroid_tab[7][14] = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment