[FFmpeg-devel] [PATCH] lavfi/atempo: fix range check if tempo is set by command

Wang Bin wbsecg1 at gmail.com
Wed Oct 3 18:47:50 EEST 2018


Nicolas George <george at nsup.org> 于2018年10月3日周三 下午11:05写道:

> wbsecg1 at gmail.com (2018-10-03):
> > From: wang-bin <wbsecg1 at gmail.com>
> >
> > ---
> >  libavfilter/af_atempo.c | 11 ++++++-----
> >  1 file changed, 6 insertions(+), 5 deletions(-)
> >
> > diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c
> > index 52f15f2769..1a004212a7 100644
> > --- a/libavfilter/af_atempo.c
> > +++ b/libavfilter/af_atempo.c
> > @@ -331,9 +331,10 @@ static int yae_set_tempo(AVFilterContext *ctx,
> const char *arg_tempo)
> >          return AVERROR(EINVAL);
> >      }
> >
> > -    if (tempo < 0.5 || tempo > 2.0) {
> > -        av_log(ctx, AV_LOG_ERROR, "Tempo value %f exceeds [0.5, 2.0]
> range\n",
> > -               tempo);
>
> > +    const AVOption *o = av_opt_find(&atempo->class, "tempo", NULL, 0,
> AV_OPT_SEARCH_FAKE_OBJ);
> > +    if (tempo < o->min || tempo > o->max) {
>
> The option is defined in the very same file and the min and max values
> are hardcoded there. There is no need for a fragile lookup.
>
>
Less mistakes. For example the author forgot to change this line. This
function is not frequently called.


> > +        av_log(ctx, AV_LOG_ERROR, "Tempo value %f exceeds [%.1f, %.1f]
> range\n",
> > +               tempo, o->min, o->max);
> >          return AVERROR(EINVAL);
> >      }
> >
> > @@ -439,8 +440,8 @@ static int yae_load_data(ATempoContext *atempo,
> >          return 0;
> >      }
> >
>
> > -    // samples are not expected to be skipped, unless tempo is greater
> than 2:
> > -    av_assert0(read_size <= atempo->ring || atempo->tempo > 2.0);
> > +    // samples are not expected to be skipped:
> > +    av_assert0(read_size <= atempo->ring);
>
> Looks unrelated. Can you explain?
>

av_opt_set or avfilter_process_command already returns error if out of
range. So no need to check it again.


More information about the ffmpeg-devel mailing list