[FFmpeg-devel] [PATCH] seek_print: Check stream index

Michael Niedermayer michaelni at gmx.at
Wed Mar 20 12:19:48 CET 2013


On Wed, Mar 20, 2013 at 11:47:16AM +0100, Nicolas George wrote:
> Le nonidi 29 ventôse, an CCXXI, Michael Niedermayer a écrit :
> > Fixes CID991858
> > 
> > Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> > ---
> >  tools/seek_print.c |    4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/tools/seek_print.c b/tools/seek_print.c
> > index a99a0ad..a6e9466 100644
> > --- a/tools/seek_print.c
> > +++ b/tools/seek_print.c
> > @@ -93,6 +93,10 @@ int main(int argc, char **argv)
> >              }
> >          } else if (sscanf(*argv, "seek:%i:%"PRIi64":%"PRIi64":%"PRIi64":%i",
> >                     &stream, &min_ts, &ts, &max_ts, &flags) == 5) {
> > +            if (stream < -1 || stream >= avf->nb_streams) {
> > +                fprintf(stderr, "Invalid stream index %d\n", stream);
> > +                return 1;
> > +            }
> >              ret = avformat_seek_file(avf, stream, min_ts, ts, max_ts, flags);
> >              printf("seek: %d (%s)\n", ret, av_err2str(ret));
> >          } else {
> 
> IMHO, this test should be in avformat_seek_file(), to cover all possible
> uses. Something like that (untested):
>

> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 5cf3d9c..2dc8217 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -2137,6 +2137,8 @@ int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int
>  {
>      if(min_ts > ts || max_ts < ts)
>          return -1;
> +    if (stream_index < -1 || stream_index >= s->nb_streams)
> +        return AVERROR(EINVAL);

this needs (int)s->nb_streams or -1 fails

otherwise LGTM

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In a rich man's house there is no place to spit but his face.
-- Diogenes of Sinope
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130320/0464ab68/attachment.asc>


More information about the ffmpeg-devel mailing list