From patchwork Sat Aug 25 16:04:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stebbins X-Patchwork-Id: 10132 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp4624117jap; Sat, 25 Aug 2018 09:04:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYpr26F7JSJgOycrk57Wj7HGIkMoSxfZqbzCuwqMsuijk97ja2Gm3XfbQI5epGLu3rzj12B X-Received: by 2002:adf:9b11:: with SMTP id b17-v6mr4380919wrc.119.1535213099356; Sat, 25 Aug 2018 09:04:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535213099; cv=none; d=google.com; s=arc-20160816; b=gxuUESrC5JqwRVoDGEQy3FG9c93wxOcoElPc8FEQsfRBuLHvXP0451Q4SKxpTGbJjM 27LxOXT/Ok+k9kCeeKdfTHYDWcfSixW/C1wXL7GsM4BxY6/7qkLNRIQa4XKW1WN0CM8S FaBLG4Q8RSEZr1Eh7ph54kNZM8/zFsl4P96LA+AX97GgTFxBz/VSYwLk2IgCjqoEF/3i iX1WozEFNZmx+cinFJfx+3UrOpYqNFqnPXCILyPsN/N7ATs4AY+akBGpqdl7IJTuSNYe irXe67m+yI0NxJRynQO0G8jEjaIe/vb5OIvZ5Aw4lQYhANWZqInzWQldKLZ1Ebcm0d8+ 3lgg== 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=rLmB171M5CfFGFp0MZEWYAB/r133Jdv2M5J5jbQRwvk=; b=hRKQ8kqK/Qj+2oSlCciks9rMDrdDxiYse0pdmswx6LECGOudNtZ2TOIEHEtQIr2SQm WkN/+t3djn8K5EP9R39QCkgIxPFdAyuk/Q+V3l1yZmE8EaQdLZVqrpVEnEexi3MnReEr um5mvC3ghvHM1ITa2gDBTo++/a6FUREb3BWKupfKbflqxsJB2rnBJqp5DNrmUH0u2ebQ uZkAF4pd4DPVdKHJzrzLykOqQUf2SOyNw49VyRy1rIUx8sbD1GqBN60olTFnR5LIunSq F7tv75jN/tu+DqGVdHqCZXJbAyGauhsbjilNQO6IDUjH1l7k/VYp6DV9tmpLxcartDli RlNQ== 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 l6-v6si7383740wrr.340.2018.08.25.09.04.58; Sat, 25 Aug 2018 09:04:59 -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 8348A689A63; Sat, 25 Aug 2018 19:04:54 +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 D23886883BD for ; Sat, 25 Aug 2018 19:04:47 +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; Sat, 25 Aug 2018 09:04:48 -0700 Received: from dionysus.jetheaddev.com (localhost [127.0.0.1]) by dionysus.jetheaddev.com (8.15.2/8.14.7) with ESMTP id w7PG4mvh011312 for ; Sat, 25 Aug 2018 09:04:48 -0700 Received: (from jstebbins@localhost) by dionysus.jetheaddev.com (8.15.2/8.15.2/Submit) id w7PG4lL1011311 for ffmpeg-devel@ffmpeg.org; Sat, 25 Aug 2018 09:04:47 -0700 From: John Stebbins To: Date: Sat, 25 Aug 2018 09:04:44 -0700 Message-ID: <20180825160444.11263-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] 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 | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 72a6e12d52..93bb50ce86 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -1589,6 +1589,26 @@ static const AVCodecTag codec_cover_image_tags[] = { { AV_CODEC_ID_NONE, 0 }, }; +static int validate_codec_tag(const AVCodecTag *const *tags, + unsigned int tag, int codec_id) +{ + 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 (codec_tags->tag == tag && codec_tags->id == codec_id) { + return 1; + } + codec_tags++; + } + } + return 0; +} + static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track) { int tag; @@ -1596,23 +1616,21 @@ static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track) 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 + + if (track->mode == MODE_MOV) tag = mov_get_codec_tag(s, track); + else + if (!validate_codec_tag(s->oformat->codec_tag, track->par->codec_tag, + track->par->codec_id)) + tag = 0; + else + tag = track->par->codec_tag; return tag; }