From patchwork Sun Sep 25 21:54:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 720 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp1616470vsd; Sun, 25 Sep 2016 14:54:19 -0700 (PDT) X-Received: by 10.28.161.133 with SMTP id k127mr12015186wme.103.1474840459245; Sun, 25 Sep 2016 14:54:19 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id cw2si1024146wjb.91.2016.09.25.14.54.18; Sun, 25 Sep 2016 14:54:19 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 99C76689B99; Mon, 26 Sep 2016 00:53:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe02-1.mx.upcmail.net (vie01a-dmta-pe02-1.mx.upcmail.net [62.179.121.157]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8E2D3689933 for ; Mon, 26 Sep 2016 00:53:52 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe02.mx.upcmail.net with esmtp (Exim 4.87) (envelope-from ) id 1boHNA-0005V9-KT for ffmpeg-devel@ffmpeg.org; Sun, 25 Sep 2016 23:54:08 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id nxu71t0090S5wYM01xu83i; Sun, 25 Sep 2016 23:54:08 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 25 Sep 2016 23:54:00 +0200 Message-Id: <20160925215400.4042-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.9.3 Subject: [FFmpeg-devel] [PATCH] avformat/utils: Discard huge timestamps which would cause overflows if used in basic computations 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Allowing larger timestamps makes it impossible to calculate basic things like the difference of 2 timestamps or their sum without checking each individual computation for overflow. This should avoid a significant number of overflow checks Fixes Ticket5136 Signed-off-by: Michael Niedermayer --- libavformat/utils.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libavformat/utils.c b/libavformat/utils.c index 3e0f57d..d227e24 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -833,6 +833,12 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) continue; } + if ( (pkt->dts != AV_NOPTS_VALUE && (pkt->dts <= INT64_MIN/2 || pkt->dts >= INT64_MAX/2)) + || (pkt->pts != AV_NOPTS_VALUE && (pkt->pts <= INT64_MIN/2 || pkt->pts >= INT64_MAX/2))) { + av_log(s, AV_LOG_WARNING, "Ignoring huge timestamps %"PRId64" %"PRId64"\n", pkt->dts, pkt->pts); + pkt->dts = pkt->pts = AV_NOPTS_VALUE; + } + st = s->streams[pkt->stream_index]; if (update_wrap_reference(s, st, pkt->stream_index, pkt) && st->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) {