From patchwork Fri Aug 5 22:54:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Snowhill X-Patchwork-Id: 104 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.67 with SMTP id o64csp1943940vsd; Fri, 5 Aug 2016 16:06:36 -0700 (PDT) X-Received: by 10.194.142.198 with SMTP id ry6mr72916559wjb.62.1470438393618; Fri, 05 Aug 2016 16:06:33 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x2si20168797wjm.38.2016.08.05.16.06.31; Fri, 05 Aug 2016 16:06:33 -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; dkim=neutral (body hash did not verify) header.i=@gmail.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; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3E9A268A67B; Sat, 6 Aug 2016 02:06:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw0-f194.google.com (mail-yw0-f194.google.com [209.85.161.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9722668A67B for ; Sat, 6 Aug 2016 02:06:04 +0300 (EEST) Received: by mail-yw0-f194.google.com with SMTP id u134so22183242ywg.3 for ; Fri, 05 Aug 2016 16:06:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yS9L6G+S9KKXzGEu8NoY7gtwoSfzfzQPlzAzD2EJMxo=; b=QwTnUU2bH0KM9d0f0OLjue9pMM5EUzmyLNbDj8VbtUQF3budeoK5onEu5WIBGohTXg F8AO+afa6eUwgYsrEFdrm/x7EVUb0cGUdoo4Z9dyKiIYoo7kSj6HMflJXFsb53EzsgJW mqbvvP4gwuTMoyWCjSdug7EObFAebbI+Po+FLsv2naA7xEUlErAcVwscUqyLXk7t+5te T8E3cnIj+ROMXjK+RdJvojMFFtHyYBC9cdV5RBlGDG2fP4Rj1kuhLDSVbyUJS8OvglIE EsrBHN4vUcTyCbHwIHtocsjmUZ/2v51AkMkaDuCaMKPUQaHeMl7r+qIT4LvP71B9UB6j aNbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yS9L6G+S9KKXzGEu8NoY7gtwoSfzfzQPlzAzD2EJMxo=; b=QhFNmiMaqSLjdQlXPCgrk3lRtTSpSl7V+TzNCr7a/ncLVjC2mG+rwFy/CL72Bw9Y8G JcQH87vcq1S6eyohA9/SyYsMolAiIiH1EQ2LQA2tRsow9VL9dGFdzSllV9PIIew8/cSd tYmRvhIDVK9ASrLuApEcGMmd+M2gsfRcZDkSKrFNdwRKg4ZAb3ZhR7NJwymV8V7LbLKG JdwneUAdlui4lRKvwK8IK/wwsmacc1Ugi2GZIRHrFMm0ZwyTH3EqpT+raqupIVvtapon BR1136xRW2uiyai0ErHg+xXp2kHe8on1UXnIjwRj/26cNCkzQAXb57aM7pbnpWv66Cqd +lfw== X-Gm-Message-State: AEkooutgv4HFl4FM7xMSvH0aZ6lxt/0RVHsxmPCGUp5L1pqlgT4BuHwxo11Oq8OFZ/83nA== X-Received: by 10.13.238.6 with SMTP id x6mr58287156ywe.212.1470437675548; Fri, 05 Aug 2016 15:54:35 -0700 (PDT) Received: from localhost.localdomain (99-11-158-33.lightspeed.irvnca.sbcglobal.net. [99.11.158.33]) by smtp.gmail.com with ESMTPSA id r186sm8883949ywr.38.2016.08.05.15.54.33 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 05 Aug 2016 15:54:34 -0700 (PDT) From: kode54@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Aug 2016 15:54:24 -0700 Message-Id: <1470437665-78199-1-git-send-email-kode54@gmail.com> X-Mailer: git-send-email 2.7.4 (Apple Git-66) In-Reply-To: <20160723110334.GB22139@nb4> References: <20160723110334.GB22139@nb4> Subject: [FFmpeg-devel] [PATCHv3 1/2] avformat: read id3v2 comment tags 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 Cc: Chris Moeller MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Chris Moeller Let's try and get this right, one last time. No uninitialized variables, no problems with unsynchronized or compressed frames, etc. --- libavformat/id3v2.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c index 46b9394..380a982 100644 --- a/libavformat/id3v2.c +++ b/libavformat/id3v2.c @@ -400,6 +400,45 @@ error: } /** + * Parse a comment tag. + */ +static void read_comment(AVFormatContext *s, AVIOContext *pb, int taglen, + AVDictionary **metadata) +{ + const char *key = "comment"; + uint8_t *dst; + int encoding, dict_flags = AV_DICT_DONT_OVERWRITE | AV_DICT_DONT_STRDUP_VAL; + int language; + + if (taglen < 4) + return; + + encoding = avio_r8(pb); + language = avio_rl24(pb); + taglen -= 4; + + if (decode_str(s, pb, encoding, &dst, &taglen) < 0) { + av_log(s, AV_LOG_ERROR, "Error reading comment frame, skipped\n"); + return; + } + + if (dst && dst[0]) { + key = (const char *) dst; + dict_flags |= AV_DICT_DONT_STRDUP_KEY; + } + + if (decode_str(s, pb, encoding, &dst, &taglen) < 0) { + av_log(s, AV_LOG_ERROR, "Error reading comment frame, skipped\n"); + if (dict_flags & AV_DICT_DONT_STRDUP_KEY) + av_freep((void*)&key); + return; + } + + if (dst) + av_dict_set(metadata, key, (const char *) dst, dict_flags); +} + +/** * Parse GEOB tag into a ID3v2ExtraMetaGEOB struct. */ static void read_geobtag(AVFormatContext *s, AVIOContext *pb, int taglen, @@ -908,6 +947,7 @@ static void id3v2_parse(AVIOContext *pb, AVDictionary **metadata, /* check for text tag or supported special meta tag */ } else if (tag[0] == 'T' || !memcmp(tag, "USLT", 4) || + !memcmp(tag, "COMM", 4) || (extra_meta && (extra_func = get_extra_meta_func(tag, isv34)))) { pbx = pb; @@ -975,6 +1015,8 @@ static void id3v2_parse(AVIOContext *pb, AVDictionary **metadata, read_ttag(s, pbx, tlen, metadata, tag); else if (!memcmp(tag, "USLT", 4)) read_uslt(s, pbx, tlen, metadata); + else if (!memcmp(tag, "COMM", 4)) + read_comment(s, pbx, tlen, metadata); else /* parse special meta tag */ extra_func->read(s, pbx, tlen, tag, extra_meta, isv34);