[FFmpeg-devel,1/3] avformat/utils: Check rfps_duration_sum for overflow

Submitted by Michael Niedermayer on July 4, 2019, 11:28 p.m.

Details

Message ID 20190704232835.32235-1-michael@niedermayer.cc
State Accepted
Commit 5c46fdf305caac8bf2f270e69e60ae3d614df468
Headers show

Commit Message

Michael Niedermayer July 4, 2019, 11:28 p.m.
Fixes: signed integer overflow: 9151595917793558550 + 297519050751678697 cannot be represented in type 'long'
Fixes: 15496/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5722866475073536

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

Comments

Michael Niedermayer July 19, 2019, 4:18 p.m.
On Fri, Jul 05, 2019 at 01:28:33AM +0200, Michael Niedermayer wrote:
> Fixes: signed integer overflow: 9151595917793558550 + 297519050751678697 cannot be represented in type 'long'
> Fixes: 15496/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5722866475073536
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavformat/utils.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

will apply

[...]

Patch hide | download patch | download mbox

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 886cd6fd83..2e8b2e8a0b 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3347,8 +3347,10 @@  int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts)
                 }
             }
         }
-        st->info->duration_count++;
-        st->info->rfps_duration_sum += duration;
+        if (st->info->rfps_duration_sum <= INT64_MAX - duration) {
+            st->info->duration_count++;
+            st->info->rfps_duration_sum += duration;
+        }
 
         if (st->info->duration_count % 10 == 0) {
             int n = st->info->duration_count;