[FFmpeg-devel] [PATCH 2/3] lavfi/af_amerge: check for buffer queue overflows.

Nicolas George nicolas.george at normalesup.org
Thu Jan 31 14:39:08 CET 2013

Without that test, ff_bufqueue_add silently discards the
oldest buffer, that leaves in[i].nb_samples inconsistent,
and causes later a segfault.

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
 libavfilter/af_amerge.c |    5 +++++
 1 file changed, 5 insertions(+)

Note: the input from Vertical400kbit.sorenson3.mov is _very_ unbalanced,
amerge receives 730 samples on one input before ffmpeg simply tries to
bother about decoding the other file. The default queue size is 32, it
can be raised, but is it wise? Inserting a FIFO would probably work in this
particular case, but not as efficiently.

diff --git a/libavfilter/af_amerge.c b/libavfilter/af_amerge.c
index 44b71e4..e552682 100644
--- a/libavfilter/af_amerge.c
+++ b/libavfilter/af_amerge.c
@@ -231,6 +231,11 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *insamples)
         if (inlink == ctx->inputs[input_number])
     av_assert1(input_number < am->nb_inputs);
+    if (ff_bufqueue_is_full(&am->in[input_number].queue)) {
+        av_log(ctx, AV_LOG_ERROR, "Buffer queue overflow\n");
+        avfilter_unref_buffer(insamples);
+        return AVERROR(ENOMEM);
+    }
     ff_bufqueue_add(ctx, &am->in[input_number].queue, insamples);
     am->in[input_number].nb_samples += insamples->audio->nb_samples;
     nb_samples = am->in[0].nb_samples;

More information about the ffmpeg-devel mailing list