Skip to content

Commit

Permalink
FLAC: Stop moving padding blocks
Browse files Browse the repository at this point in the history
`PADDING` blocks were incorrectly getting moved to the end of the header without the `Last-metadata-block` getting set.
  • Loading branch information
Serial-ATA committed Aug 25, 2024
1 parent 0b903e9 commit 03047bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- This behavior already exists for OGG formats.

### Fixed
- **FLAC**: Stop writing invalid `PADDING` blocks ([issue](https://github.com/Serial-ATA/lofty-rs/issues/442)) ([PR](https://github.com/Serial-ATA/lofty-rs/pull/446))
- If a `PADDING` block existed in the original file, and it wasn't placed at the end of the header, it would
moved without setting the `Last-metadata-block` flag. This would cause decoders to believe that the file was missing
- **Fuzzing** (Thanks [@qarmin](https://github.com/qarmin)!) ([PR](https://github.com/Serial-ATA/lofty-rs/pull/444)):
- **MusePack**: Fix panic when tag sizes exceed the stream length ([issue](https://github.com/Serial-ATA/lofty-rs/issues/440))
- **AAC**: Fix panic when tag sizes exceed the stream length ([issue](https://github.com/Serial-ATA/lofty-rs/issues/439))
Expand Down
13 changes: 10 additions & 3 deletions lofty/src/flac/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ where

let mut cursor = Cursor::new(file_bytes);

let mut padding = false;
// TODO: We need to actually use padding (https://github.com/Serial-ATA/lofty-rs/issues/445)
let mut end_padding_exists = false;
let mut last_block_info = (
stream_info.byte,
stream_info.start as usize,
Expand Down Expand Up @@ -103,14 +104,20 @@ where
tag.vendor = Cow::Owned(vendor_str);
},
BLOCK_ID_PICTURE => blocks_to_remove.push((start, end)),
BLOCK_ID_PADDING => padding = true,
BLOCK_ID_PADDING => {
if last_block {
end_padding_exists = true
} else {
blocks_to_remove.push((start, end))
}
},
_ => {},
}
}

let mut file_bytes = cursor.into_inner();

if !padding {
if !end_padding_exists {
if let Some(preferred_padding) = write_options.preferred_padding {
log::warn!("File is missing a PADDING block. Adding one");

Expand Down

0 comments on commit 03047bb

Please sign in to comment.