-
-
Notifications
You must be signed in to change notification settings - Fork 54
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