From patchwork Mon Dec 27 11:11:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 32930 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp10197060iog; Mon, 27 Dec 2021 03:11:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1nSXVzg+r6JKXKF5hljOoJszTKxYiVhUHhjjy38KkJ/hcIPhqylpEGI3ksW3i4XBrcq+h X-Received: by 2002:a05:6402:490:: with SMTP id k16mr16107189edv.99.1640603494650; Mon, 27 Dec 2021 03:11:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640603494; cv=none; d=google.com; s=arc-20160816; b=jzqQUGDswp+J6VBFdv4fuF4R5uUT1GtRUS7de6KHcY0E7wfxTqxHModFCttgCR2zic LSWGHDJFjpAgSz4yXQco6sCXk6eluwoaEvl6Mh2uaZiWZRuZ1/dsrNnjebk+GSmszv51 u5w+gAFjBNiWaEulmS6kCEQWhrVmMxdU14vyECGhCOCIIC10P2LjaAjsWwbWn9+flR0k P8XuE9Z6UoN+zWm6moHnr7TApaBdHleB0R0gDjBxbyhoJnGywkndeqiwtnoO3UFjB8+5 EhDH+aqPwOJuW9f4RCrcLEDupxu6qvlvfQUSXOUxO2SBKTuZ4Ss6zGvaBAAV6q59VBxZ HW7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to:date :to:from:message-id:dkim-signature:delivered-to; bh=dQVFayZ3JHyoIV5exGi1MKbq1pSAyOXwN1vXQFnhZ3E=; b=reZi6Sg6mVNc69Iab8xuiZ8J4UhJDBXt5Q/VIL0BQXn+qNxdiCG/qLEKejSMtxVzaE 4UrVLqSriLKap3Od/Df8tTHsNN7TEcaiMFvCLRYy1zdlBKXmRCxO5lK35l5uxO8M7YcB qXWTE1VX2FaChXUnKP7Ad0KgNGzf+BE+fODffpYFZRm4P9kibNOasf1zqvKTszC+Vclf zp5/KzdPerA/q3Se5Dq74oJSN/elqC9cEa/eQJyUr6O0LyVESvB8Mf0HPTZeSBdN8ifD sD9q9m9KbIO5lRr385JHzEz66nmPIVEFtmlRoUJQHA3uqfkjcRi9V/uAictsfprQw+tE yXoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=qjjDh3ep; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g12si7337837ejt.418.2021.12.27.03.11.33; Mon, 27 Dec 2021 03:11:34 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=qjjDh3ep; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3317368B083; Mon, 27 Dec 2021 13:11:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: aDEtQvUjUuP1 --- 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)