Cannot use metaflac to remove non-STREAMINFO block 0
I've come across some mis-encoded FLAC files that have a metadata block 0 that isn't a STREAMINFO block (STREAMINFO is present at block 1 instead). Unfortunately, the way the core loop of metaflac's do_major_operation__remove function is written appears to mean it always skips over the first block.
I assume this is by design to prevent the footgun of removing STREAMINFO, but as flac itself will refuse to decode files with metadata malformed in this manner, it does appear to make it impossible to repair them with only Xiph.org tooling.
Is it possible for you to supply such a file? Have you tried re-encoding them with flac's decode-through-errors option? That's -F or --decode-through-errors
I'll see if I saved any of them somewhere, but I'm not finding it too likely. I did attempt --decode-through-errors at the time, and it did not work. I ended up needing to use ffmpeg to decode them.
I've just tried this, and flac happily decodes such a malformed file without any problems. I actually get a warning that seems to be made specifically for this purpose:
$ flac -d test-nostreaminfo.flac
flac 1.4.1
Copyright (C) 2000-2009 Josh Coalson, 2011-2022 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.
test-nostreaminfo.flac: WARNING, cannot check MD5 signature since there was no STREAMINFO
done
Perhaps you tried to re-encode the file? This indeed doesn't work, because it will try to copy metadata, which isn't possible (because the metadata is invalid)
So it is possible to repair such a file with Xiph tooling it turns out: one has to decode the file, re-encode it, and then manually re-add the metadata (for example with metaflac --export-tags-to=somefile.txt brokenfile.flac and metaflac --import-tags-from=somefile.txt fixedfile.flac)