Skip to content

FLAC corruption in 0.23.3 #640

Closed

Description

@abique

Reproducer

I tried this code:

pub fn save_standard_metadata(&self) -> anyhow::Result<()> {
        let mut tagged_file = lofty::read_from_path(&self.source.path)?;
        let tag = match tagged_file.primary_tag_mut() {
            Some(primary_tag) => primary_tag,
            None => {
                if let Some(first_tag) = tagged_file.first_tag_mut() {
                    first_tag
                } else {
                    let tag_type = tagged_file.primary_tag_type();

                    eprintln!("WARN: No tags found, creating a new tag of type `{tag_type:?}`");
                    tagged_file.insert_tag(Tag::new(tag_type));
                    tagged_file.primary_tag_mut().unwrap()
                }
            }
        };

        if let Some(title) = &self.md.title {
            tag.set_title(title.clone());
        }

        if let Some(artist) = &self.md.artist {
            tag.set_artist(artist.clone());
        }

        if let Some(remixer) = &self.md.remixer {
            tag.insert_text(lofty::tag::ItemKey::Remixer, remixer.clone());
        }

        if let Some(label) = &self.md.label {
            tag.insert_text(lofty::tag::ItemKey::Label, label.clone());
        }

        if let Some(album) = &self.md.album {
            tag.set_album(album.clone());
        }

        if let Some(bpm) = &self.md.bpm {
            tag.insert_text(lofty::tag::ItemKey::Bpm, bpm.to_string());

            // Get rid of the integer key...
            tag.remove_key(lofty::tag::ItemKey::IntegerBpm);
        }

        if let Some(rating) = self.md.rating {
            tag.insert_text(lofty::tag::ItemKey::Popularimeter, rating.to_string());
        }

        if let Some(comment) = &self.md.comment {
            tag.set_comment(comment.clone());
        }

        if let Some(genre) = &self.md.genre {
            tag.set_genre(genre.clone());
        }

        if let Some(year) = &self.md.year {
            tag.insert(TagItem::new(
                lofty::tag::ItemKey::Year,
                ItemValue::Text(format!("{}", *year)),
            ));
        }

        if let Some(color) = &self.md.color {
            tag.insert_text(lofty::tag::ItemKey::Color, color.to_string());
        }

        tagged_file.save_to_path(&self.source.path, lofty::config::WriteOptions::default())?;
        Ok(())
    }

Summary

This will corrupt my flac files:

flac -t *.flac

flac 1.5.0
Copyright (C) 2000-2009  Josh Coalson, 2011-2025  Xiph.Org Foundation
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

01 - Insane Creatures - Fang Tooth (154 Bpm).flac: *** Got error code 0:FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC after processing 21315071 samples


01 - Insane Creatures - Fang Tooth (154 Bpm).flac: ERROR during decoding
                                                   state = FLAC__STREAM_DECODER_END_OF_STREAM
02 - Insane Creatures - Kodama´s Octopus (158 Bpm).flac: *** Got error code 0:FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC after processing 21133309 samples


02 - Insane Creatures - Kodama´s Octopus (158 Bpm).flac: ERROR during decoding
                                                          state = FLAC__STREAM_DECODER_END_OF_STREAM
03 - Insane Creatures & Senskrypt - Unveiling The Hydra´s Dream (156 Bpm).flac: ok
04 - Insane Creatures - Luna Negra (158 Bpm).flac: *** Got error code 0:FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC after processing 21088480 samples


04 - Insane Creatures - Luna Negra (158 Bpm).flac: ERROR during decoding
                                                   state = FLAC__STREAM_DECODER_END_OF_STREAM
05 - Insane Creatures & Leakowr - Synaptic Reef (160 Bpm).flac: ok
06 - Insane Creatures - Elementos (160 Bpm).flac: *** Got error code 0:FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC after processing 22523673 samples


06 - Insane Creatures - Elementos (160 Bpm).flac: ERROR during decoding
                                                  state = FLAC__STREAM_DECODER_END_OF_STREAM
07 - Insane Creatures - Complexities Of The Deep (162 Bpm).flac: ok
08 - Insane Creatures & Koorow - Subaquatic Reveries (162 Bpm).flac: ok
09 - Insane Creatures - The Dwellers Tangerine (164 Bpm).flac: *** Got error code 0:FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC after processing 18464768 samples


09 - Insane Creatures - The Dwellers Tangerine (164 Bpm).flac: ERROR while decoding data
                                                               state = FLAC__STREAM_DECODER_ABORTED

Expected behavior

No response

Assets

No response

Activity

  1. added
    bug
    on Apr 9, 2026
  2. Serial-ATA commented on Apr 10, 2026

    @Serial-ATA
    Owner

    Can you email one of the files to serial AT [domain on my profile]?

  3. abique commented on Apr 10, 2026

    @abique
    Author

    Sent.

  4. Serial-ATA commented on Apr 10, 2026

    @Serial-ATA
    Owner

    Thanks! I'll take a look soon

  5. abique commented on Apr 10, 2026

    @abique
    Author

    Thank you very much :-)

  6. Serial-ATA commented on Apr 11, 2026

    @Serial-ATA
    Owner

    This was broken all the way back in #583, surprised it didn't come up earlier. Can you test #641 against the original files?

  7. added this to the 0.24.0 milestone on Apr 12, 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