Skip to content

TagType::remove_from_path always fails: file is opened read-only (0.25.4) #750

Closed

Description

@ad-si

Description

TagType::remove_from_path (and therefore TagExt::remove_from_path) always fails in 0.25.4 with failed to write to file, caused by Bad file descriptor (os error 9).

remove_from_path builds the file via VerifiedFile::new_from_path, which uses Probe::open. That opens the file with File::open, so it's read-only. do_remove then tries to write to it.

TagExt::save_to_path isn't affected because it opens the file with OpenOptions::new().read(true).write(true) itself.

Reproducer

use lofty::config::WriteOptions;
use lofty::id3::v2::Id3v2Tag;
use lofty::prelude::{Accessor, TagExt};
use lofty::tag::TagType;

fn main() {
    // Any MP3 file
    let path = std::env::temp_dir().join("lofty-remove-repro.mp3");
    std::fs::copy(std::env::args().nth(1).unwrap(), &path).unwrap();

    let mut tag = Id3v2Tag::new();
    tag.set_title("Title".to_string());
    tag.save_to_path(&path, WriteOptions::default()).unwrap();

    let result = TagType::Id3v2.remove_from_path(&path, WriteOptions::default());
    match result {
        Ok(()) => println!("ok"),
        Err(e) => {
            println!("{e}");
            let mut source = std::error::Error::source(&e);
            while let Some(cause) = source {
                println!("caused by: {cause}");
                source = cause.source();
            }
        }
    }
}

Output:

failed to write to file
caused by: Bad file descriptor (os error 9)

Expected behavior

The tag is removed, as in 0.24.

Workaround

Open the file read-write yourself and use remove_from:

let mut file = std::fs::OpenOptions::new().read(true).write(true).open(&path)?;
TagType::Id3v2.remove_from(&mut file, WriteOptions::default())?;

Version

lofty 0.25.4 (main still has the same VerifiedFile::new_from_path → Probe::open path), macOS

Activity

  1. added
    bug
    on Oct 16, 2026
  2. added this to the 0.25.5 milestone on Oct 16, 2026
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