Skip to content

Commit 03047bb

Browse files
committed
FLAC: Stop moving padding blocks
`PADDING` blocks were incorrectly getting moved to the end of the header without the `Last-metadata-block` getting set.
1 parent 0b903e9 commit 03047bb

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- This behavior already exists for OGG formats.
1212

1313
### Fixed
14+
- **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))
15+
- If a `PADDING` block existed in the original file, and it wasn't placed at the end of the header, it would
16+
moved without setting the `Last-metadata-block` flag. This would cause decoders to believe that the file was missing
1417
- **Fuzzing** (Thanks [@qarmin](https://github.com/qarmin)!) ([PR](https://github.com/Serial-ATA/lofty-rs/pull/444)):
1518
- **MusePack**: Fix panic when tag sizes exceed the stream length ([issue](https://github.com/Serial-ATA/lofty-rs/issues/440))
1619
- **AAC**: Fix panic when tag sizes exceed the stream length ([issue](https://github.com/Serial-ATA/lofty-rs/issues/439))

lofty/src/flac/write.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ where
6161

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

64-
let mut padding = false;
64+
// TODO: We need to actually use padding (https://github.com/Serial-ATA/lofty-rs/issues/445)
65+
let mut end_padding_exists = false;
6566
let mut last_block_info = (
6667
stream_info.byte,
6768
stream_info.start as usize,
@@ -103,14 +104,20 @@ where
103104
tag.vendor = Cow::Owned(vendor_str);
104105
},
105106
BLOCK_ID_PICTURE => blocks_to_remove.push((start, end)),
106-
BLOCK_ID_PADDING => padding = true,
107+
BLOCK_ID_PADDING => {
108+
if last_block {
109+
end_padding_exists = true
110+
} else {
111+
blocks_to_remove.push((start, end))
112+
}
113+
},
107114
_ => {},
108115
}
109116
}
110117

111118
let mut file_bytes = cursor.into_inner();
112119

113-
if !padding {
120+
if !end_padding_exists {
114121
if let Some(preferred_padding) = write_options.preferred_padding {
115122
log::warn!("File is missing a PADDING block. Adding one");
116123

0 commit comments

Comments
 (0)