From patchwork Fri Sep 16 00:08:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 599 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp179902vsd; Thu, 15 Sep 2016 17:12:13 -0700 (PDT) X-Received: by 10.28.52.73 with SMTP id b70mr5266736wma.109.1473984733050; Thu, 15 Sep 2016 17:12:13 -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 le9si3371322wjc.201.2016.09.15.17.12.08; Thu, 15 Sep 2016 17:12:13 -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 F3606689EE8; Fri, 16 Sep 2016 03:11:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe04-1.mx.upcmail.net (vie01a-dmta-pe04-1.mx.upcmail.net [62.179.121.163]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1D609689E0E for ; Fri, 16 Sep 2016 03:11:46 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe04.mx.upcmail.net with esmtp (Exim 4.87) (envelope-from ) id 1bkgl4-0002ij-K4 for ffmpeg-devel@ffmpeg.org; Fri, 16 Sep 2016 02:11:58 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id k0Bx1t00W0S5wYM010BylF; Fri, 16 Sep 2016 02:11:58 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 16 Sep 2016 02:08:14 +0200 Message-Id: <20160916000814.31108-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.9.3 Subject: [FFmpeg-devel] [PATCH] avformat/movenc: Make the packet check more tolerant 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" Depends-on "avformat/movenc: Check packet in mov_write_single_packet() too" Signed-off-by: Michael Niedermayer --- libavformat/movenc.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index b704f49..aa4a076 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -4666,25 +4666,26 @@ static int check_pkt(AVFormatContext *s, AVPacket *pkt) { MOVMuxContext *mov = s->priv_data; MOVTrack *trk = &mov->tracks[pkt->stream_index]; + int64_t ref; + uint64_t duration; if (trk->entry) { - int64_t duration = pkt->dts - trk->cluster[trk->entry - 1].dts; - if (duration < 0 || duration > INT_MAX) { - av_log(s, AV_LOG_ERROR, "Application provided duration: %"PRId64" / timestamp: %"PRId64" is out of range for mov/mp4 format\n", - duration, pkt->dts - ); - - pkt->dts = trk->cluster[trk->entry - 1].dts + 1; - pkt->pts = AV_NOPTS_VALUE; - } - } else if (pkt->dts <= INT_MIN || pkt->dts >= INT_MAX) { - av_log(s, AV_LOG_ERROR, "Application provided initial timestamp: %"PRId64" is out of range for mov/mp4 format\n", - pkt->dts - ); + ref = trk->cluster[trk->entry - 1].dts; + } else if (trk->start_dts != AV_NOPTS_VALUE) { + ref = trk->start_dts + trk->track_duration; + } else + ref = pkt->dts; // Skip tests for the first packet - pkt->dts = 0; - pkt->pts = AV_NOPTS_VALUE; + duration = pkt->dts - ref; + if (pkt->dts < ref || duration >= INT_MAX) { + av_log(s, AV_LOG_ERROR, "Application provided duration: %"PRId64" / timestamp: %"PRId64" is out of range for mov/mp4 format\n", + duration, pkt->dts + ); + + pkt->dts = ref + 1; + pkt->pts = AV_NOPTS_VALUE; } + if (pkt->duration < 0 || pkt->duration > INT_MAX) { av_log(s, AV_LOG_ERROR, "Application provided duration: %"PRId64" is invalid\n", pkt->duration); return AVERROR(EINVAL);