Skip to content

incorrect disc number handling in ape tag writer #545

@AyaseFile

Description

@AyaseFile

Reproducer

use std::path::Path;

use lofty::prelude::*;
use lofty::tag::{ItemKey, TagType};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    {
        let mut ape_tag = lofty::ape::ApeTag::new();
        ape_tag.set_track(2);
        ape_tag.set_track_total(10);
        ape_tag.set_disk(3);
        ape_tag.set_disk_total(5);
        println!("before `remove_disk_total`:");
        println!(
            "- Track: {}/{}",
            ape_tag.track().unwrap_or(0),
            ape_tag.track_total().unwrap_or(0)
        );
        println!(
            "- Disk: {}/{}",
            ape_tag.disk().unwrap_or(0),
            ape_tag.disk_total().unwrap_or(0)
        );
        ape_tag.remove_disk_total();
        println!("after `remove_disk_total`:");
        println!(
            "- Track: {}/{}",
            ape_tag.track().unwrap_or(0),
            ape_tag.track_total().unwrap_or(0)
        );
        println!(
            "- Disk: {}/{}",
            ape_tag.disk().unwrap_or(0),
            ape_tag.disk_total().unwrap_or(0)
        );
    }
    {
        let test_file = Path::new("test.wv");
        let mut tagged_file = lofty::read_from_path(test_file)?;
        if let Some(tag) = tagged_file.tag_mut(TagType::Ape) {
            tag.insert_text(ItemKey::DiscNumber, "3".to_string());
            tag.insert_text(ItemKey::DiscTotal, "5".to_string());
            tagged_file.save_to_path(test_file, Default::default())?;
        }
    }
    Ok(())
}

Summary

There are two bugs in the APE tag writer related to disc number handling:

  • Incorrect logic in remove_disk_total: The method incorrectly preserves the track number instead of the disc number.
  • Incorrect key written to file: The writer uses the key "Disk" instead of the correct "Disc". This was verified on WavPack files using FFmpeg and Picard.

Expected behavior

The output of the reproducer code should be:

before `remove_disk_total`:
- Track: 2/10
- Disk: 3/5
after `remove_disk_total`:
- Track: 2/10
- Disk: 3/0

After writing to the WavPack file, inspecting it with ffprobe -i <any_wavpack_file>.wv should show the correct metadata, including a Disc tag with the value 3/5.

Assets

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions