From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 87CE5501C9 for ; Tue, 8 Jul 2025 22:07:59 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id DDF0968F0D8; Wed, 9 Jul 2025 01:07:54 +0300 (EEST) Date: Tue, 8 Jul 2025 18:07:35 -0400 To: FFmpeg development discussions and patches MIME-Version: 1.0 Message-ID: List-Id: FFmpeg development discussions and patches List-Post: From: Nil Fons Miret via ffmpeg-devel Precedence: list Cc: Nil Fons Miret , Kyle Swanson X-Mailman-Version: 2.1.29 X-BeenThere: ffmpeg-devel@ffmpeg.org List-Subscribe: , List-Unsubscribe: , List-Archive: Reply-To: FFmpeg development discussions and patches List-Help: Subject: [FFmpeg-devel] [PATCH] avformat/demux: avoid unconditional ID3v2 tag consumption Content-Type: multipart/mixed; boundary="===============4320480256563517925==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============4320480256563517925== Content-Type: message/rfc822 Content-Disposition: inline Return-Path: X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 3610968080D for ; Wed, 9 Jul 2025 01:07:48 +0300 (EEST) Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-7179205a439so4106217b3.1 for ; Tue, 08 Jul 2025 15:07:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netflix.com; s=google; t=1752012466; x=1752617266; darn=ffmpeg.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=s/mWk/cQxk8uaPBzOd9WoF0dn5HiklWns1bvf0brHx4=; b=GWI09v9VzBZ514eVpqhIV0p/SjQBxG4s9iKNct4Cpq+OhfjpIy49+hvfIQ6oAzHK2W RcUz7+b4Cl0oKJDX4GWXJqjTrCvf5HsbNiwk/OTkhNjR3Aw5qcl+AZRI/9KuAzvbsMG/ 4ZtwR6AMLMbxs3E4Jmxe1xj2sYLS20ULikdCY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752012466; x=1752617266; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=s/mWk/cQxk8uaPBzOd9WoF0dn5HiklWns1bvf0brHx4=; b=si4xLrbWE9b6yiS30dOgo74tGuHmGM8nsyHtFpQgx8QUh3rxGY6az8cnhiiaCIgIyN 0ZQHb4bRpRj8VQ0i4WGFuk0duGaASS9a+BXyKs4dnCujOns+TULX0UOUr7yMSSGgHZXB zgGo8iYYiv60lNmlJAnnPWnVCTfnvXuOG97HgJI5Y+1BX+FzBTynnzqbsLbQ+YIkHAOw iQ0oxqRtbZq3tqSaOpbmvckqkQ02fCMqslpALuerMUOrnjvd7wMiLv1w5RAQW3lYGgdp o/4NQPX8Syn21tsVy0yLcUlGnzSbCHvX2YC398U+nGmZeNx0ZRNQF5z5r+DmhXeKxrjL UKYA== X-Gm-Message-State: AOJu0Yz+6J0wt4H+a52LOHC/HOcx1TCXmhq4+vdh3cbE3Xl1KePS2buj /GE/9220qzovVt/UROjk9s0E9BB7a3EPt2atglNFMIEE3nJmE3uma6gXOikvFl32lDrx7FgdQIP Mg/qqgkYUX3Atfd4flQXma+t96No5dSBlPmpZmg7mrkDGV9kZzYmozUI= X-Gm-Gg: ASbGncvjDcOYyEoXwUefcP261xm64ODZ2O1ODe4NLNVHRuRZxOhCwASj6jU7ww1GHaS T7MBEPiFqlVti5W64VZr2H//nDrB8974k8Y1tB+tuVHFqFiWhi5zyAYkU59ziyw3goB0mSBLx4r ygLbWcEF/VeTsC9/I61rZnaC7g2Uqc8dCuNu9peiagHwj3V8iM07+uzQ== X-Google-Smtp-Source: AGHT+IEOwGfzzJAlao4QWFfZROyatjrdGGMHohqVtKn9Y7K/dkW3eq0Ku5pjynHFkrKF/xI24sRNwDqpQQwFtJbb180= X-Received: by 2002:a05:690c:c99:b0:712:c5f7:1eef with SMTP id 00721157ae682-717b2cd5625mr381947b3.3.1752012466472; Tue, 08 Jul 2025 15:07:46 -0700 (PDT) MIME-Version: 1.0 From: Nil Fons Miret Date: Tue, 8 Jul 2025 18:07:35 -0400 X-Gm-Features: Ac12FXz_9CzbjYohQwC8t8_1AaiWjr-Kw7CwiFe6ACwA3lTuneTLCZ5F9fFchus Message-ID: Subject: [PATCH] avformat/demux: avoid unconditional ID3v2 tag consumption To: FFmpeg development discussions and patches Cc: Kyle Swanson Content-Type: multipart/mixed; boundary="000000000000b55a3006397230fe" --000000000000b55a3006397230fe Content-Type: text/plain; charset="UTF-8" I have found a few instances of rawvideo files that coincidentally start with a header matching the ID3v2 header format, and ffmpeg consumes the header before demuxing, causing a decoding error. This happens even if "-f rawvideo" is specified. This patch limits the formats for which this automatic consuming of ID3v2 headers is done. Note: I am not an expert in ID3v2 by any means, and I'm happy to accept suggestions, both on the scope and mechanism of the solution. To reproduce, you can easily generate an example as follows: ``` ( echo "49 44 33 2B 98 3A 49 44 33 2B 98 3A 6A 44 54 2B" | xxd -r -p dd if=/dev/zero bs=1 count=115184 2>/dev/null ) > id3v2_320x240_yuv420p.yuv ffmpeg -f rawvideo -s 320x240 -pix_fmt yuv420p -i id3v2_320x240_yuv420p.yuv -f null - ``` This generates a 320x240 yuv420p file with a 16-byte header that matches the ID3v2 header format (this was copied from a real case I saw) and completed with zeroes for a total of 115200 bytes, the right size for this resolution and pixel format. On the master branch, I see: ``` [...] ID3v2.43 tag skipped, cannot handle version [...] [out#0/null @ 0x15700a6e0] Output file is empty, nothing was encoded(check -ss / -t / -frames parameters if used) frame= 0 fps=0.0 q=0.0 Lsize=N/A time=N/A bitrate=N/A speed=N/A ``` After the changes: it decodes as expected. ``` [...] frame= 1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A speed=16.5x elapsed=0:00:00.00 ``` Thanks in advance, Nil --000000000000b55a3006397230fe Content-Type: message/rfc822; name="0001-avformat-demux-avoid-unconditional-ID3v2-tag-consumpti.eml" Content-Disposition: attachment; filename="0001-avformat-demux-avoid-unconditional-ID3v2-tag-consumpti.eml" Content-ID: X-Attachment-Id: f_mcv2x5yl0 From: nilfm Date: Wed, 2 Jul 2025 14:37:24 -0400 Subject: [PATCH] avformat/demux: avoid unconditional ID3v2 tag consumption X-Unsent: 1 To: ffmpeg-devel@ffmpeg.org ID3v2 headers are now only parsed for formats that explicitly support them, avoiding premature data consumption that broke demuxing in other formats. Introduces AVFMT_FLAG_ID3V2_AUTO and applies it to mp3, aac, tta, and wav. Signed-off-by: nilfm --- libavformat/aacdec.c | 2 +- libavformat/avformat.h | 1 + libavformat/demux.c | 9 ++++++--- libavformat/mp3dec.c | 2 +- libavformat/tta.c | 1 + libavformat/wavdec.c | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c index 0b4bd69dd2..21d63ce189 100644 --- a/libavformat/aacdec.c +++ b/libavformat/aacdec.c @@ -208,7 +208,7 @@ retry: const FFInputFormat ff_aac_demuxer = { .p.name = "aac", .p.long_name = NULL_IF_CONFIG_SMALL("raw ADTS AAC (Advanced Audio Coding)"), - .p.flags = AVFMT_GENERIC_INDEX, + .p.flags = AVFMT_GENERIC_INDEX | AVFMT_FLAG_ID3V2_AUTO, .p.extensions = "aac", .p.mime_type = "audio/aac,audio/aacp,audio/x-aac", .read_probe = adts_aac_probe, diff --git a/libavformat/avformat.h b/libavformat/avformat.h index b6c63e2237..6fe4559a6f 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1435,6 +1435,7 @@ typedef struct AVFormatContext { #define AVFMT_FLAG_SORT_DTS 0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down) #define AVFMT_FLAG_FAST_SEEK 0x80000 ///< Enable fast, but inaccurate seeks for some formats #define AVFMT_FLAG_AUTO_BSF 0x200000 ///< Add bitstream filters as requested by the muxer +#define AVFMT_FLAG_ID3V2_AUTO 0x400000 ///< Automatically parse ID3v2 metadata /** * Maximum number of bytes read from input in order to determine stream diff --git a/libavformat/demux.c b/libavformat/demux.c index 3749ab67a3..dfc146d9c4 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -214,6 +214,10 @@ static int update_stream_avctx(AVFormatContext *s) return 0; } +static av_always_inline int is_id3v2_format(const AVInputFormat *fmt) { + return fmt->flags & AVFMT_FLAG_ID3V2_AUTO; +} + int avformat_open_input(AVFormatContext **ps, const char *filename, const AVInputFormat *fmt, AVDictionary **options) { @@ -302,7 +306,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, } /* e.g. AVFMT_NOFILE formats will not have an AVIOContext */ - if (s->pb) + if (s->pb && is_id3v2_format(s->iformat)) ff_id3v2_read_dict(s->pb, &si->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta); if (ffifmt(s->iformat)->read_header) @@ -321,8 +325,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, } if (id3v2_extra_meta) { - if (!strcmp(s->iformat->name, "mp3") || !strcmp(s->iformat->name, "aac") || - !strcmp(s->iformat->name, "tta") || !strcmp(s->iformat->name, "wav")) { + if (is_id3v2_format(s->iformat)) { if ((ret = ff_id3v2_parse_apic(s, id3v2_extra_meta)) < 0) goto close; if ((ret = ff_id3v2_parse_chapters(s, id3v2_extra_meta)) < 0) diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 31eeb68ebb..9cfc711493 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -618,7 +618,7 @@ static const AVClass demuxer_class = { const FFInputFormat ff_mp3_demuxer = { .p.name = "mp3", .p.long_name = NULL_IF_CONFIG_SMALL("MP2/3 (MPEG audio layer 2/3)"), - .p.flags = AVFMT_GENERIC_INDEX, + .p.flags = AVFMT_GENERIC_INDEX | AVFMT_FLAG_ID3V2_AUTO, .p.extensions = "mp2,mp3,m2a,mpa", /* XXX: use probe */ .p.priv_class = &demuxer_class, .p.mime_type = "audio/mpeg", diff --git a/libavformat/tta.c b/libavformat/tta.c index fdc18216c8..26335202c7 100644 --- a/libavformat/tta.c +++ b/libavformat/tta.c @@ -191,6 +191,7 @@ static int tta_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp const FFInputFormat ff_tta_demuxer = { .p.name = "tta", .p.long_name = NULL_IF_CONFIG_SMALL("TTA (True Audio)"), + .p.flags = AVFMT_FLAG_ID3V2_AUTO, .p.extensions = "tta", .priv_data_size = sizeof(TTAContext), .read_probe = tta_probe, diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index c65e0a2723..4c47a5f05c 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -1011,7 +1011,7 @@ static const AVClass w64_demuxer_class = { const FFInputFormat ff_w64_demuxer = { .p.name = "w64", .p.long_name = NULL_IF_CONFIG_SMALL("Sony Wave64"), - .p.flags = AVFMT_GENERIC_INDEX, + .p.flags = AVFMT_GENERIC_INDEX | AVFMT_FLAG_ID3V2_AUTO, .p.codec_tag = ff_wav_codec_tags_list, .p.priv_class = &w64_demuxer_class, .priv_data_size = sizeof(WAVDemuxContext), -- 2.47.1 --000000000000b55a3006397230fe-- --===============4320480256563517925== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============4320480256563517925==--