diff mbox series

[FFmpeg-devel,1/2] avformat/mvdec: Fix integer overflow with billions of channels

Message ID 20200623001458.15855-1-michael@niedermayer.cc
State Accepted
Headers show
Series [FFmpeg-devel,1/2] avformat/mvdec: Fix integer overflow with billions of channels | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Michael Niedermayer June 23, 2020, 12:14 a.m. UTC
Fixes: signed integer overflow: 1394614304 * 2 cannot be represented in type 'int'
Fixes: 23491/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5697377020411904

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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andreas Rheinhardt June 23, 2020, 3:22 a.m. UTC | #1
Michael Niedermayer:
> Fixes: signed integer overflow: 1394614304 * 2 cannot be represented in type 'int'
> Fixes: 23491/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5697377020411904
> 
> 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 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/mvdec.c b/libavformat/mvdec.c
> index 64166a84b1..fa87384c6b 100644
> --- a/libavformat/mvdec.c
> +++ b/libavformat/mvdec.c
> @@ -355,7 +355,7 @@ static int mv_read_header(AVFormatContext *avctx)
>              avio_skip(pb, 8);
>              av_add_index_entry(ast, pos, timestamp, asize, 0, AVINDEX_KEYFRAME);
>              av_add_index_entry(vst, pos + asize, i, vsize, 0, AVINDEX_KEYFRAME);
> -            timestamp += asize / (ast->codecpar->channels * 2);
> +            timestamp += asize / (ast->codecpar->channels * 2LL);
>          }
>      } else if (!version && avio_rb16(pb) == 3) {
>          avio_skip(pb, 4);
> 
You could avoid using 64 the 64 bit intermediate by multiplying with 2U
or by using asize / ast->codecpar->channels / 2.

Whatever you prefer should also be applied to read_index.

- Andreas
Michael Niedermayer June 26, 2020, 8:13 p.m. UTC | #2
On Tue, Jun 23, 2020 at 05:22:53AM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Fixes: signed integer overflow: 1394614304 * 2 cannot be represented in type 'int'
> > Fixes: 23491/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5697377020411904
> > 
> > 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 | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/libavformat/mvdec.c b/libavformat/mvdec.c
> > index 64166a84b1..fa87384c6b 100644
> > --- a/libavformat/mvdec.c
> > +++ b/libavformat/mvdec.c
> > @@ -355,7 +355,7 @@ static int mv_read_header(AVFormatContext *avctx)
> >              avio_skip(pb, 8);
> >              av_add_index_entry(ast, pos, timestamp, asize, 0, AVINDEX_KEYFRAME);
> >              av_add_index_entry(vst, pos + asize, i, vsize, 0, AVINDEX_KEYFRAME);
> > -            timestamp += asize / (ast->codecpar->channels * 2);
> > +            timestamp += asize / (ast->codecpar->channels * 2LL);
> >          }
> >      } else if (!version && avio_rb16(pb) == 3) {
> >          avio_skip(pb, 4);
> > 
> You could avoid using 64 the 64 bit intermediate by multiplying with 2U
> or by using asize / ast->codecpar->channels / 2.
> 
> Whatever you prefer should also be applied to read_index.

will apply to both

thanks

[...]
diff mbox series

Patch

diff --git a/libavformat/mvdec.c b/libavformat/mvdec.c
index 64166a84b1..fa87384c6b 100644
--- a/libavformat/mvdec.c
+++ b/libavformat/mvdec.c
@@ -355,7 +355,7 @@  static int mv_read_header(AVFormatContext *avctx)
             avio_skip(pb, 8);
             av_add_index_entry(ast, pos, timestamp, asize, 0, AVINDEX_KEYFRAME);
             av_add_index_entry(vst, pos + asize, i, vsize, 0, AVINDEX_KEYFRAME);
-            timestamp += asize / (ast->codecpar->channels * 2);
+            timestamp += asize / (ast->codecpar->channels * 2LL);
         }
     } else if (!version && avio_rb16(pb) == 3) {
         avio_skip(pb, 4);