Skip to content

Mp3Extractor: Support files with (slightly) incorrectly declared ID3 tag lengths #811

Closed

Description

@Tolriq

Version

Media3 pre-release (alpha, beta or RC not in this list)

More version details

Any version but tested with 1.2.0

Devices that reproduce the issue

All

Devices that do not reproduce the issue

None

Reproducible in the demo app?

Yes

Reproduction steps

Try to play a file with multiple large ID3 headers.
Like a small ID3 v1 header followed by an ID3 header larger than 32k

The extractor sniff will fail because only the first ID3 header is taken in account and skipped, so the sniff does not reach the proper frames before the end of the second ID3 header.

Second header that should either be skipped or handled for the gapless data / metadata don't know if there should be a priorisation of ID3 v2 tags over v1 when both are present.

Expected result

The media should play

Actual result

The media does not play because the sniff return false due to large second ID3 header.

Media

I can send in private if necessary.

Bug Report

Activity

  1. rohitjoins commented on Nov 15, 2023

    @rohitjoins
    Contributor

    Hi @Tolriq,

    Can you please send the media via email for me to take a look?

  2. Tolriq commented on Nov 15, 2023

    @Tolriq
    ContributorAuthor

    Sent.

  3. Tolriq commented on Jul 21, 2025

    @Tolriq
    ContributorAuthor

    Small why not bump. Still an issue. My local hack is just an hack not good enough to upstream.

    Subject: [PATCH] If the file start with ID3 increase the max sniff size
    ---
    Index: libraries/extractor/src/main/java/androidx/media3/extractor/mp3/Mp3Extractor.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    diff --git a/libraries/extractor/src/main/java/androidx/media3/extractor/mp3/Mp3Extractor.java b/libraries/extractor/src/main/java/androidx/media3/extractor/mp3/Mp3Extractor.java
    --- a/libraries/extractor/src/main/java/androidx/media3/extractor/mp3/Mp3Extractor.java	(revision 07c45b3c4180d0da4d92f76ff0ff3a8c69b029ca)
    +++ b/libraries/extractor/src/main/java/androidx/media3/extractor/mp3/Mp3Extractor.java	(revision a37d893d9b226e2923b4d478d3aae76e4efe54bf)
    @@ -395,6 +395,9 @@
             input.skipFully(peekedId3Bytes);
           }
         }
    +    if (peekedId3Bytes > 0) {
    +      searchLimitBytes = MAX_SYNC_BYTES;
    +    }
         while (true) {
           if (peekEndOfStreamOrHeader(input)) {
             if (validFrameCount > 0) {
    
    
  4. icbaker commented on Jul 22, 2025

    @icbaker
    Collaborator

    ExoPlayer's Id3Peeker does try to read multiple ID3 tags with the while loop in Id3Peeker (in order to handle the case you describe). We try and advance to the start of the next tag with this line:

    In the case of the provided file, this advances one byte too few, so this check fails (because we read 0x094944 = <TAB>ID instead of 0x494443 = ID3).

    if (scratch.readUnsignedInt24() != Id3Decoder.ID3_TAG) {
    // Not an ID3 tag.
    break;
    }

    The first ID3 tag in this file represents its length as 0x00001070, which is a 'synch safe' int where the MSB of each byte is zero (and ignored), so this evaluates to 2160 in decimal. This is the length without the 10 byte ID3 header (but does include padding) [1], so the next ID3 tag should start at byte 2170, but in fact it starts at 2171.

    We can add some fuzziness to the search for the next ID3 tag, but this media is not spec-compliant, so marking this as a feature request rather than a bug.


    [1] From https://id3.org/d3v2.3.0

    The ID3v2 tag size is the size of the complete tag after unsychronisation, including padding, excluding the header but not excluding the extended header (total tag size - 10).

  5. changed the title [-]Mp3Extractor do not properly support multiple ID3 headers at file start[/-] [+]Mp3Extractor: Support files with (slightly) incorrectly declared ID3 tag lengths[/+] on Jul 22, 2025
  6. icbaker commented on Jul 29, 2025

    @icbaker
    Collaborator

    This is fixed by the commit linked above.

  7. locked and limited conversation to collaborators on Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions