diff options
author | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2014-09-02 23:50:55 +0200 |
---|---|---|
committer | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2014-09-07 11:31:33 +0200 |
commit | 2231d5b67185674ddd1703abf92ea0020f63ca04 (patch) | |
tree | df23b640813ad8ff8eac593aeb7ca8f77a8275d0 /libswresample/rematrix.c | |
parent | ab84effdeda931a74d8503891488ed538619a5d3 (diff) | |
download | ffmpeg-2231d5b67185674ddd1703abf92ea0020f63ca04.tar.gz |
libswresample: Avoid needlessly large on-stack array.
We only actually need to use a tiny part of it.
Unfortunately we seem to have no real test coverage on
the code, so this is a bit risky.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Diffstat (limited to 'libswresample/rematrix.c')
-rw-r--r-- | libswresample/rematrix.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c index bf2abcfb20..62662f8368 100644 --- a/libswresample/rematrix.c +++ b/libswresample/rematrix.c @@ -56,6 +56,7 @@ #define TOP_BACK_LEFT 15 #define TOP_BACK_CENTER 16 #define TOP_BACK_RIGHT 17 +#define NUM_NAMED_CHANNELS 18 int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride) { @@ -112,7 +113,7 @@ static int sane_layout(int64_t layout){ av_cold static int auto_matrix(SwrContext *s) { int i, j, out_i; - double matrix[64][64]={{0}}; + double matrix[NUM_NAMED_CHANNELS][NUM_NAMED_CHANNELS]={{0}}; int64_t unaccounted, in_ch_layout, out_ch_layout; double maxcoef=0; char buf[128]; @@ -145,7 +146,7 @@ av_cold static int auto_matrix(SwrContext *s) } memset(s->matrix, 0, sizeof(s->matrix)); - for(i=0; i<64; i++){ + for(i=0; i<FF_ARRAY_ELEMS(matrix); i++){ if(in_ch_layout & out_ch_layout & (1ULL<<i)) matrix[i][i]= 1.0; } @@ -299,9 +300,12 @@ av_cold static int auto_matrix(SwrContext *s) double sum=0; int in_i=0; for(j=0; j<64; j++){ - s->matrix[out_i][in_i]= matrix[i][j]; - if(matrix[i][j]){ - sum += fabs(matrix[i][j]); + if (i < FF_ARRAY_ELEMS(matrix) && j < FF_ARRAY_ELEMS(matrix[0])) + s->matrix[out_i][in_i]= matrix[i][j]; + else + s->matrix[out_i][in_i]= i == j && (in_ch_layout & out_ch_layout & (1ULL<<i)); + if(s->matrix[out_i][in_i]){ + sum += fabs(s->matrix[out_i][in_i]); } if(in_ch_layout & (1ULL<<j)) in_i++; |