TianyiShi2001 / audiotags

Unified IO for different types of audio metadata
https://tianyishi2001.github.io/audiotags
MIT License
41 stars 29 forks source link

metaflac dependencies index out of range #30

Closed devimalka closed 6 months ago

devimalka commented 1 year ago

i'm working on this music player i use audiotags to parse the metadata when the flac files are parsing some flac files parsing panic the program due to issue with the metaflac dependencie

thread 'main' panicked at 'range end index 4 out of range for slice of length 0', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/metaflac-0.2.5/src/block.rs:355:26ss

use audiotags::{Tag,Error};

#[derive(Debug)]
pub struct Tags{
    pub title: String,
    pub artist: String,
    pub year: String,
    pub genre: String,
    pub track_number: u16,
    pub duration: f64,
    pub album_cover: Vec<u8>

}

pub fn read_tag(path: &str) -> Result<Tags, Option<Error>> {
    let tag = Tag::new().read_from_path(path)?;
    let title = match tag.title(){
        Some(title) => title.to_string(),
        None => "No Title".to_string(),
    };
    let artist = match tag.artist(){
        Some(artist) => artist.to_string(),
        None => "No artist found".to_string(),
    };
    let year = match tag.year() {
        Some(year) => year.to_string(),
        None => "".to_string(),
    };
    let genre = match tag.genre() {
        Some(genre) => genre.to_string(),
        None => "".to_string(),
    };
    let track_number = match tag.track_number(){
        Some(number) => number,
        None => 0,
    };
    let duration = match tag.duration(){
        Some(duration) => duration,
        None => 0.0,
    };

    let album_cover = match tag.album_cover(){
        Some(picture) => picture.data.to_vec(),
        None => Vec::new(),
    };

    Ok(
        Tags{
            title,
            artist,
            year,
            genre,
            track_number,
            duration,
            album_cover,
        }
    )

}`

please find the function i created for parsing tags

Serial-ATA commented 1 year ago

Your file has a non spec-compliant application block. The metaflac crate makes a lot of assumptions about your input and isn't prepared for much invalid/unexpected data. This is not the only reported case of a panic in the case of malformed inputs.

This is not an issue that can be solved within audiotags, and with the metaflac crate pretty much being abandoned at this point, there isn't much you can do outside of repairing your broken files.

pinkforest commented 6 months ago

I created a new issue to replace metaflac with a fork we can upstream from there.

Closing this in favor of one tracking issue