diff mbox series

[FFmpeg-devel,4/9] avformat/wtvdec: Improve size overflow checks in parse_chunks()

Message ID 20210419182346.4445-4-michael@niedermayer.cc
State Accepted
Commit f8ec1da8ac8e3daf2403e744f166ea9557b2d333
Headers show
Series [FFmpeg-devel,1/9] avformat/utils: check dts/duration to be representable before using them | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Michael Niedermayer April 19, 2021, 6:23 p.m. UTC
Fixes: signed integer overflow: 32 + 2147483647 cannot be represented in type 'int
Fixes: 32967/clusterfuzz-testcase-minimized-ffmpeg_dem_WTV_fuzzer-5132856218222592

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/wtvdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Peter Ross April 21, 2021, 8:28 a.m. UTC | #1
On Mon, Apr 19, 2021 at 08:23:41PM +0200, Michael Niedermayer wrote:
> Fixes: signed integer overflow: 32 + 2147483647 cannot be represented in type 'int
> Fixes: 32967/clusterfuzz-testcase-minimized-ffmpeg_dem_WTV_fuzzer-5132856218222592
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavformat/wtvdec.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c
> index 44ca86d517..2f1b192cea 100644
> --- a/libavformat/wtvdec.c
> +++ b/libavformat/wtvdec.c
> @@ -809,7 +809,7 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p
>                  avio_skip(pb, 12);
>                  ff_get_guid(pb, &formattype);
>                  size = avio_rl32(pb);
> -                if (size < 0 || size > INT_MAX - 92)
> +                if (size < 0 || size > INT_MAX - 92 - consumed)
>                      return AVERROR_INVALIDDATA;
>                  parse_media_type(s, 0, sid, mediatype, subtype, formattype, size);
>                  consumed += 92 + size;
> @@ -825,7 +825,7 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p
>                  avio_skip(pb, 12);
>                  ff_get_guid(pb, &formattype);
>                  size = avio_rl32(pb);
> -                if (size < 0 || size > INT_MAX - 76)
> +                if (size < 0 || size > INT_MAX - 76 - consumed)
>                      return AVERROR_INVALIDDATA;
>                  parse_media_type(s, s->streams[stream_index], sid, mediatype, subtype, formattype, size);
>                  consumed += 76 + size;
> -- 

please apply

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
Michael Niedermayer April 22, 2021, 2:01 p.m. UTC | #2
On Wed, Apr 21, 2021 at 06:28:41PM +1000, Peter Ross wrote:
> On Mon, Apr 19, 2021 at 08:23:41PM +0200, Michael Niedermayer wrote:
> > Fixes: signed integer overflow: 32 + 2147483647 cannot be represented in type 'int
> > Fixes: 32967/clusterfuzz-testcase-minimized-ffmpeg_dem_WTV_fuzzer-5132856218222592
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavformat/wtvdec.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c
> > index 44ca86d517..2f1b192cea 100644
> > --- a/libavformat/wtvdec.c
> > +++ b/libavformat/wtvdec.c
> > @@ -809,7 +809,7 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p
> >                  avio_skip(pb, 12);
> >                  ff_get_guid(pb, &formattype);
> >                  size = avio_rl32(pb);
> > -                if (size < 0 || size > INT_MAX - 92)
> > +                if (size < 0 || size > INT_MAX - 92 - consumed)
> >                      return AVERROR_INVALIDDATA;
> >                  parse_media_type(s, 0, sid, mediatype, subtype, formattype, size);
> >                  consumed += 92 + size;
> > @@ -825,7 +825,7 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p
> >                  avio_skip(pb, 12);
> >                  ff_get_guid(pb, &formattype);
> >                  size = avio_rl32(pb);
> > -                if (size < 0 || size > INT_MAX - 76)
> > +                if (size < 0 || size > INT_MAX - 76 - consumed)
> >                      return AVERROR_INVALIDDATA;
> >                  parse_media_type(s, s->streams[stream_index], sid, mediatype, subtype, formattype, size);
> >                  consumed += 76 + size;
> > -- 
> 
> please apply

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c
index 44ca86d517..2f1b192cea 100644
--- a/libavformat/wtvdec.c
+++ b/libavformat/wtvdec.c
@@ -809,7 +809,7 @@  static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p
                 avio_skip(pb, 12);
                 ff_get_guid(pb, &formattype);
                 size = avio_rl32(pb);
-                if (size < 0 || size > INT_MAX - 92)
+                if (size < 0 || size > INT_MAX - 92 - consumed)
                     return AVERROR_INVALIDDATA;
                 parse_media_type(s, 0, sid, mediatype, subtype, formattype, size);
                 consumed += 92 + size;
@@ -825,7 +825,7 @@  static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p
                 avio_skip(pb, 12);
                 ff_get_guid(pb, &formattype);
                 size = avio_rl32(pb);
-                if (size < 0 || size > INT_MAX - 76)
+                if (size < 0 || size > INT_MAX - 76 - consumed)
                     return AVERROR_INVALIDDATA;
                 parse_media_type(s, s->streams[stream_index], sid, mediatype, subtype, formattype, size);
                 consumed += 76 + size;