From patchwork Mon Aug 27 21:11:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stebbins X-Patchwork-Id: 10156 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp6873281jap; Mon, 27 Aug 2018 14:12:47 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdaercdc7cCr0P8V4rt8n2dueCw9qGWI5eXhJU8a0AtspZh4jP66OM9V/UpizYqvbAQQdnsk X-Received: by 2002:a1c:4d09:: with SMTP id o9-v6mr6820488wmh.134.1535404367067; Mon, 27 Aug 2018 14:12:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535404367; cv=none; d=google.com; s=arc-20160816; b=xENOJMJ92Pzl2f90fHa20lcdZnTbaM7vt8+BQZrFEaQ2GtlNyBJkJ1p14jbBAWuwEa IcEI/9DMD901IfP2AcQKlLnxq6OYE/ATt7K/+gbLsdDcQ+hl7JCzeA8GBJTO3La7Ri6C NUAoor4HIDP3LDo7FIVo2XTvZDrTZkIDPImzuoz7+hMbEzCTD6t8AFv/TnQuyeIYhAnQ RJF4ufL26s6GzOB6xZXKc1LypSjfMDVKPJISLYbLUcW2CsxSd/gMQZH9F7CUB+nf7tjE hO0LQclpbcjLoqykHzWEahVxoHyZ9h+kePIyeGka6mzgz27aKMrdAC33Ve+uqm918XVh UNyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to:arc-authentication-results; bh=lakufl9ulDUJvSUwC9m7IZdN+Iu3VDgy9SlmaU1F4nw=; b=IU5fVtPPPIU1+QiZ/9QheE74xKoeSxURu9n1lWy7+pVUrYFsFrhhqTIDeiR1CBEnP4 /zarTp8w0yevxjWFh8HF0rMQqsC3ucPmOylydQOJnVB6H+OtgSL8xCfwkwBQ5Wh02P0i ioxEFKN57mW3zMeYBFUB0upznBQIiCCf+sHMVbB2yXbYWtfp5M5/lPha1H5fgquxiHCL +3hcZr2W1alDz2j9jQ7z9LNRnKFTy2tvw2QhS+YlQ4YOO3tiWcaiYDcRAhW5n8470k94 ZH8vvCKGC43dOHDCIfjEYs5THQHktkQ5zuuIB4Gp07Ikz/jha5h43MYo9G0RtnvLJ0u/ 7lDw== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g14-v6si208539wrv.431.2018.08.27.14.12.46; Mon, 27 Aug 2018 14:12:47 -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 E0B7E6882CF; Tue, 28 Aug 2018 00:12:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.jetheaddev.com (mail.jetheaddev.com [70.164.99.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 592F768092E for ; Tue, 28 Aug 2018 00:12:34 +0300 (EEST) Received: from dionysus.jetheaddev.com (10.13.12.63) by cas.jetheaddev.com (192.168.13.27) with Microsoft SMTP Server (TLS) id 14.3.351.0; Mon, 27 Aug 2018 14:11:15 -0700 Received: from dionysus.jetheaddev.com (localhost [127.0.0.1]) by dionysus.jetheaddev.com (8.15.2/8.14.7) with ESMTP id w7RLBFxq025632 for ; Mon, 27 Aug 2018 14:11:15 -0700 Received: (from jstebbins@localhost) by dionysus.jetheaddev.com (8.15.2/8.15.2/Submit) id w7RLBFDQ025631 for ffmpeg-devel@ffmpeg.org; Mon, 27 Aug 2018 14:11:15 -0700 From: John Stebbins To: Date: Mon, 27 Aug 2018 14:11:14 -0700 Message-ID: <20180827211114.25566-1-jstebbins@jetheaddev.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.13.12.63] Subject: [FFmpeg-devel] [PATCH 3/3] lavf/movenc: Fail when codec tag is invalid for format 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes ticket #6897 --- libavformat/movenc.c | 46 +++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 8a3b651514..3ebc7abd8b 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -1535,9 +1535,9 @@ static int mov_get_rawvideo_codec_tag(AVFormatContext *s, MOVTrack *track) return tag; } -static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track) +static unsigned int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track) { - int tag = track->par->codec_tag; + unsigned int tag = track->par->codec_tag; if (!tag || (s->strict_std_compliance >= FF_COMPLIANCE_NORMAL && (track->par->codec_id == AV_CODEC_ID_DVVIDEO || @@ -1589,31 +1589,45 @@ static const AVCodecTag codec_cover_image_tags[] = { { AV_CODEC_ID_NONE, 0 }, }; -static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track) +static unsigned int validate_codec_tag(const AVCodecTag *const *tags, + unsigned int tag, int codec_id) { - int tag; + int i; + + /** + * Check that tag + id is in the table + */ + for (i = 0; tags && tags[i]; i++) { + const AVCodecTag *codec_tags = tags[i]; + while (codec_tags->id != AV_CODEC_ID_NONE) { + if (avpriv_toupper4(codec_tags->tag) == avpriv_toupper4(tag) && + codec_tags->id == codec_id) + return codec_tags->tag; + codec_tags++; + } + } + return 0; +} + +static unsigned int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track) +{ + unsigned int tag; if (is_cover_image(track->st)) return ff_codec_get_tag(codec_cover_image_tags, track->par->codec_id); - if (track->mode == MODE_MP4 || track->mode == MODE_PSP) - tag = track->par->codec_tag; - else if (track->mode == MODE_ISM) - tag = track->par->codec_tag; - else if (track->mode == MODE_IPOD) { + if (track->mode == MODE_IPOD) if (!av_match_ext(s->url, "m4a") && !av_match_ext(s->url, "m4v") && !av_match_ext(s->url, "m4b")) av_log(s, AV_LOG_WARNING, "Warning, extension is not .m4a nor .m4v " "Quicktime/Ipod might not play the file\n"); - tag = track->par->codec_tag; - } else if (track->mode & MODE_3GP) - tag = track->par->codec_tag; - else if (track->mode == MODE_F4V) - tag = track->par->codec_tag; - else - tag = mov_get_codec_tag(s, track); + if (track->mode == MODE_MOV) + tag = mov_get_codec_tag(s, track); + else + tag = validate_codec_tag(s->oformat->codec_tag, track->par->codec_tag, + track->par->codec_id); return tag; }