Skip to content

Corrupting flac files #549

@phayes

Description

@phayes

Reproducer

Summary

I've been running into issues with lofty corrupting flac files in the following situations:

  1. It's a "bare" flac file (eg STREAMINFO is the final block, no tag metadata, no SEEKTABLE),

  2. 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:

  1. Right here (

    last_block_info = (block.byte, (end - start) as usize, end as usize)
    ). last_block_info is 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 causes file_bytes[last_block_info.1] = first_byte; (
    file_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.

  2. If there are no blocks to remove, we corrupt the file right here (

    file_bytes.splice(0..0, comment_blocks);
    ) file_bytes.splice(0..0, comment_blocks); overwrites the first 4 fLaC bytes in the file.

Expected behavior

No response

Assets

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions