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 3D58040B31 for ; Mon, 27 Dec 2021 11:11:31 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E16FB68B07E; Mon, 27 Dec 2021 13:11:28 +0200 (EET) Received: from out162-62-57-137.mail.qq.com (out162-62-57-137.mail.qq.com [162.62.57.137]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2153168AEC8 for ; Mon, 27 Dec 2021 13:11:21 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1640603477; bh=+hjw8dgSGTj8L8hORGwDmiBZt/bpa3hVZJ/YbH1qHm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qjjDh3epakJAs4sVZcY+cl6DJAiOz0SImaYyf7M7r2TWpCnQy7OVyAiTVQZ7XJuBo flkO5wW1UQF7YjZU/LlxqRXdoPPDe1g+Kv5JfdKOsD11ru0+N7iNqtvRDJ+C9lTuLK jUzYEhjQW9Sh8Jux2smDc+NtFelyHj29cCltFjcQ= Received: from ZHILIZHAO-MB2.tencent.com ([113.108.77.56]) by newxmesmtplogicsvrszc6.qq.com (NewEsmtp) with SMTP id 2D030444; Mon, 27 Dec 2021 19:11:16 +0800 X-QQ-mid: xmsmtpt1640603476tzpejbfgi Message-ID: X-QQ-XMAILINFO: NWth7vBa++Gd7vU8ezA7WRPg26EdUPyE/nJgyjQAPZipCcbT9xKgFB98RiKpf1 w2mkDdxlK/06VqYTajePUM6h2diKFobuaAMWpzLT2JaM5HQ2+errLlhO5FDG60MSSDf7cmMNBc/h on7+hqmNtGIMbueUoI6l01/lrkLfHH3K2x+8we5YUmS3rj8Jrkxzsjux2C6mp48hD+KPHIrGu1Qt OcfItlN/wDBriXT2LTXZ2XJQgjIR6+/6wp8L1+ENSF8jaX2z0bQQAIDCoSXP840/oMa5So0UAJYn ULYjLfMcb6EYO67qaNTgoXHfl4NSNxpvWxLZGodqAqoJLfmJEY7xR+Gn9mbRPcY60GcVuOAdX9aE sI4nOjUkWOYYYzOtnFHw5QvRYKCHUvppMjkbTvvzTk9kcsomUsJIn/iE8gTFjOVstjAn2/Ewa1VX p3NCfkhZZ6TnjhVVN7yYXNpPi/ffRX9xGLPFPHJMPNv2GUhzdoAc7mu0aVOC/Cyuw+h60bEYn8Yl l51TRcBjoiJqVgDJOKZzNqw5ffTsdDsu827VEB3QqiJ0NeZRb1yJAsLIWxD9BdaxFbmVsDCsYFcS yRh46GmYAD8OAnV5fabWfiy+8QUHb3g+4HW9bpc/5At5cjwDq37yQz7EVf9oylfn4PDuYjTVd00r DLj6lfjvgOjI6hNl/nerFYKB9qoGr/S1gKYNuAfP+CBAR0NZ55+iL9T81TO5KEu3a18IllDnkuhD DLpgieBaCSX+qXeoLNIelo9WiWp9HuwkKDrBFOZAw/aCcgLZc1D9aEuKwVcWnK9hTd+tpVx8qDR0 KjZJdBSe3x7R+HUHtYRvjC2u+i4PwszUeWzpbXGjow+PmEIEddGE22EvDybELHP4lyr0W7OsmRWg == From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Dec 2021 19:11:14 +0800 X-OQ-MSGID: <20211227111114.10952-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] 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 dd92c0f26d..3f35d2939f 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".