Message ID | 20190810210949.1743-7-michael@niedermayer.cc |
---|---|
State | Accepted |
Commit | 679f3408906081036afacbc94f325793f303c039 |
Headers | show |
On Sat, Aug 10, 2019 at 11:09:48PM +0200, Michael Niedermayer wrote: > Fixes: signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'long' > Fixes: 16022/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5759796759756800 > > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> > --- > libavutil/mathematics.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) will apply [...]
diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c index 1bf044cdf1..0485db7222 100644 --- a/libavutil/mathematics.c +++ b/libavutil/mathematics.c @@ -198,7 +198,7 @@ int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t i m = inc_tb.num * (int64_t)ts_tb.den; d = inc_tb.den * (int64_t)ts_tb.num; - if (m % d == 0) + if (m % d == 0 && ts <= INT64_MAX - m / d) return ts + m / d; if (m < d) return ts; @@ -206,6 +206,10 @@ int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t i { int64_t old = av_rescale_q(ts, ts_tb, inc_tb); int64_t old_ts = av_rescale_q(old, inc_tb, ts_tb); + + if (old == INT64_MAX) + return ts; + return av_rescale_q(old + 1, inc_tb, ts_tb) + (ts - old_ts); } }
Fixes: signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'long' Fixes: 16022/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5759796759756800 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- libavutil/mathematics.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)