diff mbox series

[FFmpeg-devel,5/7] avformat/mvdec: Sanity check SAMPLE_WIDTH

Message ID 20210202231334.24412-5-michael@niedermayer.cc
State Accepted
Headers show
Series [FFmpeg-devel,1/7] avformat/utils: Extend overflow check in dts wrap in compute_pkt_fields() | 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 Feb. 2, 2021, 11:13 p.m. UTC
Fixes: signed integer overflow: 999999999 * 8 cannot be represented in type 'int'
Fixes: 30048/clusterfuzz-testcase-minimized-ffmpeg_dem_MV_fuzzer-5864289917337600

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

Comments

Peter Ross Feb. 3, 2021, 2:18 a.m. UTC | #1
On Wed, Feb 03, 2021 at 12:13:32AM +0100, Michael Niedermayer wrote:
> Fixes: signed integer overflow: 999999999 * 8 cannot be represented in type 'int'
> Fixes: 30048/clusterfuzz-testcase-minimized-ffmpeg_dem_MV_fuzzer-5864289917337600
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavformat/mvdec.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/mvdec.c b/libavformat/mvdec.c
> index d8f121bea5..ac96e4a808 100644
> --- a/libavformat/mvdec.c
> +++ b/libavformat/mvdec.c
> @@ -159,7 +159,10 @@ static int parse_audio_var(AVFormatContext *avctx, AVStream *st,
>          st->codecpar->sample_rate = var_read_int(pb, size);
>          avpriv_set_pts_info(st, 33, 1, st->codecpar->sample_rate);
>      } else if (!strcmp(name, "SAMPLE_WIDTH")) {
> -        st->codecpar->bits_per_coded_sample = var_read_int(pb, size) * 8;
> +        uint64_t bpc = var_read_int(pb, size) * (uint64_t)8;
> +        if (bpc > 100)
> +            return AVERROR_INVALIDDATA;
> +        st->codecpar->bits_per_coded_sample = bpc;
>      } else
>          return AVERROR_INVALIDDATA;

ok

could tighten it further.  realistically (audio) bits per codeded sample will never >16 here.

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
Michael Niedermayer Feb. 3, 2021, 11:11 p.m. UTC | #2
On Wed, Feb 03, 2021 at 01:18:18PM +1100, Peter Ross wrote:
> On Wed, Feb 03, 2021 at 12:13:32AM +0100, Michael Niedermayer wrote:
> > Fixes: signed integer overflow: 999999999 * 8 cannot be represented in type 'int'
> > Fixes: 30048/clusterfuzz-testcase-minimized-ffmpeg_dem_MV_fuzzer-5864289917337600
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavformat/mvdec.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavformat/mvdec.c b/libavformat/mvdec.c
> > index d8f121bea5..ac96e4a808 100644
> > --- a/libavformat/mvdec.c
> > +++ b/libavformat/mvdec.c
> > @@ -159,7 +159,10 @@ static int parse_audio_var(AVFormatContext *avctx, AVStream *st,
> >          st->codecpar->sample_rate = var_read_int(pb, size);
> >          avpriv_set_pts_info(st, 33, 1, st->codecpar->sample_rate);
> >      } else if (!strcmp(name, "SAMPLE_WIDTH")) {
> > -        st->codecpar->bits_per_coded_sample = var_read_int(pb, size) * 8;
> > +        uint64_t bpc = var_read_int(pb, size) * (uint64_t)8;
> > +        if (bpc > 100)
> > +            return AVERROR_INVALIDDATA;
> > +        st->codecpar->bits_per_coded_sample = bpc;
> >      } else
> >          return AVERROR_INVALIDDATA;
> 
> ok
> 
> could tighten it further.  realistically (audio) bits per codeded sample will never >16 here.

will apply with 16

thx

[...]
diff mbox series

Patch

diff --git a/libavformat/mvdec.c b/libavformat/mvdec.c
index d8f121bea5..ac96e4a808 100644
--- a/libavformat/mvdec.c
+++ b/libavformat/mvdec.c
@@ -159,7 +159,10 @@  static int parse_audio_var(AVFormatContext *avctx, AVStream *st,
         st->codecpar->sample_rate = var_read_int(pb, size);
         avpriv_set_pts_info(st, 33, 1, st->codecpar->sample_rate);
     } else if (!strcmp(name, "SAMPLE_WIDTH")) {
-        st->codecpar->bits_per_coded_sample = var_read_int(pb, size) * 8;
+        uint64_t bpc = var_read_int(pb, size) * (uint64_t)8;
+        if (bpc > 100)
+            return AVERROR_INVALIDDATA;
+        st->codecpar->bits_per_coded_sample = bpc;
     } else
         return AVERROR_INVALIDDATA;