[FFmpeg-cvslog] resample: allocate a large enough output buffer

Justin Ruggles git at videolan.org
Sat Mar 17 23:52:41 CET 2012


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Wed Mar 14 13:01:32 2012 -0400| [6ca3b248e21fc48418c4221fc92c2eecaf07cb9b] | committer: Justin Ruggles

resample: allocate a large enough output buffer

Fixes invalid writes and crashes when doing conversions such as stereo to 5.1
channels or sample rate conversion on 5.1 channels.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6ca3b248e21fc48418c4221fc92c2eecaf07cb9b
---

 libavcodec/resample.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/resample.c b/libavcodec/resample.c
index ba8ce89..eacffed 100644
--- a/libavcodec/resample.c
+++ b/libavcodec/resample.c
@@ -272,11 +272,13 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl
     lenout = 4 * nb_samples * s->ratio + 16;
 
     if (s->sample_fmt[1] != AV_SAMPLE_FMT_S16) {
+        int out_size = lenout * av_get_bytes_per_sample(s->sample_fmt[1]) *
+                       s->output_channels;
         output_bak = output;
 
-        if (!s->buffer_size[1] || s->buffer_size[1] < lenout) {
+        if (!s->buffer_size[1] || s->buffer_size[1] < out_size) {
             av_free(s->buffer[1]);
-            s->buffer_size[1] = lenout;
+            s->buffer_size[1] = out_size;
             s->buffer[1] = av_malloc(s->buffer_size[1]);
             if (!s->buffer[1]) {
                 av_log(s->resample_context, AV_LOG_ERROR, "Could not allocate buffer\n");



More information about the ffmpeg-cvslog mailing list