FLAC: Stop moving padding blocks

`PADDING` blocks were incorrectly getting moved to the end of the header without the `Last-metadata-block` getting set.
This commit is contained in:
Serial 2024-08-25 13:39:51 -04:00 committed by Alex
parent 0b903e9698
commit 03047bb345
2 changed files with 13 additions and 3 deletions

View file

@ -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))

View file

@ -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,
@ -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");