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

Stefano Sabatini stefasab at gmail.com
Thu Jan 31 17:57:02 CET 2013


On date Thursday 2013-01-31 14:39:08 +0100, Nicolas George encoded:
> 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.

Could you make the size parametric? Or we could set the overflow
policy in the bufqueue (increase size, discard oldest, ignore new).
 
> 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])
>              break;
>      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;
> -- 
> 1.7.10.4

Patch LGTM.
-- 
FFmpeg = Faithless and Fierce Mortal Portentous Eccentric Gangster


More information about the ffmpeg-devel mailing list