Skip to content

ID3v2: Corruption when encountering incomplete tags #721

Closed

Description

@Serial-ATA

Discussed in #720

Originally posted by incompl September 17, 2026
Hi! I’m trying to understand whether this is intended behavior or a bug in Lofty’s ID3v2 write path.

I have an otherwise ordinary, untagged MP3 which begins directly with an MPEG frame. Its audio payload happens to contain the literal bytes ID3, followed by an invalid ID3v2 major version (0xBF), several MiB into the file.

My application uses:

WriteOptions::new().parse_options(
    ParseOptions::new().max_junk_bytes(16 * 1024 * 1024),
)

to support MP3s with unusually large leading junk / stacked ID3v2 tags.

On saving a new ID3v2 tag, I believe this happens:

  1. find_id3v2 searches the allowed junk window and finds the literal ID3 inside MPEG audio.
  2. Parsing the candidate header fails, as expected, because 0xBF is not a valid ID3v2 version.
  3. The function seeks back 10 bytes, which appears to leave the reader at the false candidate rather than at its original position.
  4. The ID3v2 writer reads from that position to EOF, prepends the new tag, and rewrites the file.

The save reports success, but all bytes before the accidental ID3 sequence are lost.

My expectation would be that a failed candidate parse either:

  • restores the reader to its original position, or
  • continues searching for a valid header,

and that a raw ID3 sequence after the first MPEG frame is never treated as a leading tag candidate.
Is that expectation correct? If so, I can provide a bug with a regression test.

Activity

  1. added
    bug
    on Sep 18, 2026
  2. added this to the 0.25.3 milestone on Sep 19, 2026
  3. incompl commented on Sep 19, 2026

    @incompl

    Confirmed in my app, thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions