diff --git a/CHANGELOG.md b/CHANGELOG.md index 76aa92ff..6d62a749 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/lofty/src/flac/write.rs b/lofty/src/flac/write.rs index 57723c62..b61a6d12 100644 --- a/lofty/src/flac/write.rs +++ b/lofty/src/flac/write.rs @@ -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");