From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 6FE5A40E05 for ; Fri, 31 Dec 2021 11:36:46 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3BDBE68B01C; Fri, 31 Dec 2021 13:36:26 +0200 (EET) Received: from out203-205-221-190.mail.qq.com (out203-205-221-190.mail.qq.com [203.205.221.190]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2D6F268A8FD for ; Fri, 31 Dec 2021 13:36:15 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1640950570; bh=SJTKUSVehm7iRXQ5DpmqfwzjOYXi+S6b6dvWKe9K6CA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jGFzFekyv/DBRr67fWqLHCigqK+WlP4cnLDrCPRkjNifcUUuDtG96pncDDiHEgM5K 1RU3TYwJDrj2ORpEn0+LYM+dbf0Wu5OUJ3Pa9/F3Rq03Ak2Z23nNesNqRTciUhJhvl IIQ+VaQ9NcdWAOv3iw0HNGCSA/ZXRw7ce1a6yVLY= Received: from ZHILIZHAO-MB2.tencent.com ([113.108.77.69]) by newxmesmtplogicsvrsza5.qq.com (NewEsmtp) with SMTP id 9089FEB7; Fri, 31 Dec 2021 19:36:08 +0800 X-QQ-mid: xmsmtpt1640950569t4916s8wj Message-ID: X-QQ-XMAILINFO: N6qfSVgljG6XtE5f5yltuUdNm+TtxVoVNJ3Dlf10sNZp4mE6lBfxYizsscFAvO GLTwxTpBHxViw7mgqs9xXNQyFaMoT6JO7GNBnFJp0zCRmCHf2Iv8QgR3eZ9tmAQ05XkoNPw1uSGS Hq6QufIcJuaIZ1Nnyej9lbca4E6jOsZSGPqh5dzQhXgAY8qQpE5OiW6ryH3XZ6RUgusJcVfEUXi3 DfMDsb6DoR/4njtVcJgK3rMjEKgp8mFpVKNX/Up3sIWsOyuqzf6ogRRA8Z27wNPKfiOI6SoC04bo vuqzQ6mcz0VE8d8R0T7XA8OdheCXmfsaLkvsJMJaGwDe3B72L/aWtBVIbXiUSZxTSEPKhpWM2Kmh qxtW2/7Kyy5kLs94gUavXq5P+RnX3MaSb82wn6alzsFiFFEy3UPMFr/ujueuLaBYa2428RVkOKa5 fDdJBjYc6zTO0ZTz+da55g/VDDHZNckdHLM1V5FzvneUWHui4CONyBqYplwrxyNA6z7XhWnJO4v/ Lh3J256aAVBNfSZWD8ejcMCqLwKSkOCX3TuCTMoy4+LtUDoeqtMcVHff2PsnJz5m5E15QCalJwbl BjJHjW0pnNWqpSNcfcSJ3j/BiGw0uae6AbFLjIlipBmPQpFqCNhVkbgXVp9PVr5hd8owzdPS2Pxu NmslhbjiV/TeatgsIqAbAl/e7mx7SD0rzMb4AN9q4ejw7ZJSy0uifSxDbvf9OJS6EuXp1CDQuyDa LhQ6djLib0FDSGPU8wjusAGMQNNQOzk/q9lB3AEK1/dfKC3RzO4HEr5ZLarTM71ti0JTki5MiYfj 9rvPD2HcugojYSW32PDrFlq/t5OTP4LE1cFsxON7SkFE/Rrg/KwUW5lbzX1Bgqg9mCzLhTDIa8pQ == From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Fri, 31 Dec 2021 19:36:08 +0800 X-OQ-MSGID: <20211231113610.85358-2-quinkblack@foxmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211231113610.85358-1-quinkblack@foxmail.com> References: <20211231113610.85358-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 2/4] avformat/movenc: add missing timestamp check when peek from interleave queues X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Zhao Zhili Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- libavformat/movenc.c | 80 +++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index f5bb785b01..9b3bd99e97 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -5403,6 +5403,45 @@ static int mov_write_squashed_packets(AVFormatContext *s) return 0; } +static int check_pkt_time(AVFormatContext *s, int stream_index, + int64_t *pkt_pts, int64_t *pkt_dts, + int64_t *pkt_duration) { + MOVMuxContext *mov = s->priv_data; + MOVTrack *trk = &mov->tracks[stream_index]; + int64_t ref; + uint64_t duration; + + if (trk->entry) { + ref = trk->cluster[trk->entry - 1].dts; + } else if ( trk->start_dts != AV_NOPTS_VALUE + && !trk->frag_discont) { + ref = trk->start_dts + trk->track_duration; + } else + ref = *pkt_dts; // Skip tests for the first packet + + if (trk->dts_shift != AV_NOPTS_VALUE) { + /* With negative CTS offsets we have set an offset to the DTS, + * reverse this for the check. */ + ref -= trk->dts_shift; + } + + 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); + } + return 0; +} + static int mov_flush_fragment(AVFormatContext *s, int force) { MOVMuxContext *mov = s->priv_data; @@ -5429,12 +5468,15 @@ static int mov_flush_fragment(AVFormatContext *s, int force) if (!track->end_reliable) { const AVPacket *pkt = ff_interleaved_peek(s, i); if (pkt) { - int64_t offset, dts, pts; + int64_t offset, dts, pts, duration; ff_get_muxer_ts_offset(s, i, &offset); pts = pkt->pts + offset; dts = pkt->dts + offset; + duration = pkt->duration; if (track->dts_shift != AV_NOPTS_VALUE) dts += track->dts_shift; + if (check_pkt_time(s, pkt->stream_index, &pts, &dts, &duration)) + continue; track->track_duration = dts - track->start_dts; if (pts != AV_NOPTS_VALUE) track->end_pts = pts; @@ -5627,40 +5669,8 @@ static int mov_auto_flush_fragment(AVFormatContext *s, int force) 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) { - ref = trk->cluster[trk->entry - 1].dts; - } else if ( trk->start_dts != AV_NOPTS_VALUE - && !trk->frag_discont) { - ref = trk->start_dts + trk->track_duration; - } else - ref = pkt->dts; // Skip tests for the first packet - - if (trk->dts_shift != AV_NOPTS_VALUE) { - /* With negative CTS offsets we have set an offset to the DTS, - * reverse this for the check. */ - ref -= trk->dts_shift; - } - - 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); - } - return 0; + return check_pkt_time(s, pkt->stream_index, &pkt->pts, &pkt->dts, + &pkt->duration); } int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) -- 2.31.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".