From patchwork Sat Aug 10 21:09:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 14384 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 17C9244A476 for ; Sun, 11 Aug 2019 00:17:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F39F668ABA8; Sun, 11 Aug 2019 00:17:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe08-3.mx.upcmail.net (vie01a-dmta-pe08-3.mx.upcmail.net [84.116.36.22]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 650C068066C for ; Sun, 11 Aug 2019 00:17:18 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe08.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1hwYeF-0003LA-3a for ffmpeg-devel@ffmpeg.org; Sat, 10 Aug 2019 23:11:35 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id wYdGh60SjwlyswYdGhrKfo; Sat, 10 Aug 2019 23:10:34 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.41.20 X-CNFS-Analysis: v=2.3 cv=E5OzWpVl c=1 sm=1 tr=0 a=I1eytVlZLDX1BM2VTtTtSw==:117 a=I1eytVlZLDX1BM2VTtTtSw==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=nZOtpAppAAAA:20 a=7Ur9GJjVcGdMpnaAFHcA:9 a=LTKThHanwa3vWl4R:21 a=HFBC50FrWJtP55cO:21 a=1fhp2MxaeJtTNGEnv6mo:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=UDnyf2zBuKT2w-IlGP_r:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 10 Aug 2019 23:09:48 +0200 Message-Id: <20190810210949.1743-7-michael@niedermayer.cc> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190810210949.1743-1-michael@niedermayer.cc> References: <20190810210949.1743-1-michael@niedermayer.cc> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfHVY4FusxgfbREmieGnBbJRa7ktlo4q4KZiohAiLyyDKjM961vRJCtL7omXvoNMFa6SAe1sVKcEZsgiEQH93bWR1segEN4tx1lRKKZ2o7S7BO3jEu9fg hZ3bH1xdJDhBNg13NlP2zUshLkIVgl7fiYNCdRgLxXSGHxyPjrWcRJlT Subject: [FFmpeg-devel] [PATCH 7/8] avutil/mathematics: Fix 2 overflows in av_add_stable() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- libavutil/mathematics.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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); } }