Repository navigation
Description
Reproducer
Summary
I've been running into issues with lofty corrupting flac files in the following situations:
-
It's a "bare" flac file (eg STREAMINFO is the final block, no tag metadata, no SEEKTABLE),
-
There's no padding or metadata, just a STREAMINFO and SEEKTABLE.
I'm not entirely sure of my understanding of the bug. I've laid out below what I think is the problem, but I dont have enough confidence in my understanding to offer a PR:
-
Right here (
).lofty-rs/lofty/src/flac/write.rs
Line 83 in 2727c5c
last_block_info = (block.byte, (end - start) as usize, end as usize) last_block_infois later used as (header_first_byte, header_offset, payload_end).
You’re overwriting the header offset with (end - start) (the length), and the “header first byte” with block.byte (which is just the value of the first header byte, not an offset). This causesfile_bytes[last_block_info.1] = first_byte;() to write the “is_last” flag into a length-sized index. The causes file corruption when we need to adding a padding block.lofty-rs/lofty/src/flac/write.rs
Line 127 in 2727c5c
file_bytes[last_block_info.1] = first_byte; -
If there are no blocks to remove, we corrupt the file right here (
)lofty-rs/lofty/src/flac/write.rs
Line 152 in 2727c5c
file_bytes.splice(0..0, comment_blocks); file_bytes.splice(0..0, comment_blocks);overwrites the first 4fLaCbytes in the file.
Expected behavior
No response
Assets
No response
Activity
phayes commentedon Sep 28, 2025
I've opened a PR for this here: #550 - I would appreciate a careful review since I'm not 100% confident I'm following all the various accouting being done to keep track of things.
KRTirtho commentedon Nov 17, 2025
@Serial-ATA facing the same issue in Spotube (v5.1.0 latest) which uses
lofty-rsfor tagging. You can actually check the downloaded FLAC files withffprobeand it shows:Serial-ATA commentedon Nov 17, 2025
I did some work on #550 a bit ago, but got caught up working on other issues. I'll see if I can finish it up soon.