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

Nicolas George nicolas.george at normalesup.org
Wed Mar 20 11:47:16 CET 2013


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);
 
     if(s->seek2any>0)
         flags |= AVSEEK_FLAG_ANY;


Regards,

-- 
  Nicolas George
-------------- 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/dc6331a0/attachment.asc>


More information about the ffmpeg-devel mailing list