Repository navigation
Description
Reproducer
(Summary)
Lofty's VerifiedFile probe doesn't receive the caller's WriteOptions.parse_options, so it silently reverted to the 1,024-byte default set in ParseOptions::DEFAULT_MAX_JUNK_BYTES. The passing of WriteOptions.parse_options to VerifiedFile::new() would allow flexibility of file compatibility. Same as the #1 in [https://github.com//issues/668] which was closed, but only the second issue might have been done?
(Background)
Some of my MP3 files had more than 1024 bytes of "Junk Data" after the tag (v2.3) and before the audio section. I wanted to figure out why they were failing when the tag was being updated so I started looking into it and found that a manual edit with other software worked fine, but Lofty would just fail. Since Lofty uses only the default of 1024 bytes to search after the tag for the audio data the write was failing. If the ParseOptions::DEFAULT_MAX_JUNK_BYTES was changed to a higher number (4096?) or the WriteOptions.parse_options was used with a higher number then they would have written without error.
(Reproducer)
Attempt to add a tag to an MP3 file with more than 1024 junk bytes after the tag and before the audio stream.
Code from my update to bliss-analyser (for Lofty 0.25.1):
fn set_mp3_analysis_tag(
path: &Path,
analysis_tag: &str,
value: &str,
) -> Result<(), Box<dyn std::error::Error>> {
use lofty::id3::v2::{
ExtendedTextFrame,
Frame,
Id3v2Tag,
};
use lofty::TextEncoding;
use lofty::mpeg::MpegFile;
let mut input = std::fs::File::open(path)?;
let mut file = MpegFile::read_from(
&mut input,
ParseOptions::new(),
)?;
let tag = match file.id3v2_mut() {
Some(tag) => tag,
None => {
file.set_id3v2(Id3v2Tag::new());
file.id3v2_mut().unwrap()
}
};
tag.insert(Frame::UserText(
ExtendedTextFrame::new(
TextEncoding::UTF8,
Cow::Owned(analysis_tag.to_owned()),
Cow::Owned(value.to_owned()),
),
));
file.save_to_path(
path,
WriteOptions::default(),
)?;
(Expected Behavior)
Successful addition of new tag data.
(Actual Behavior)
Write fails with error: failed to write to file .
(Assets)
If you would like a test file I can e-mail it to you...
(After Lofty update bliss-analyser code file.save_to_path changed to:)
let write_options = WriteOptions::default()
.parse_options(ParseOptions::default().max_junk_bytes(4096));
file.save_to_path(path, write_options)?;
I did have help from AI (chatGPT) to investigate this and find what could be changed. I will attempt a PR, but have never done one before...
The details of the changes are below (AI summary since I don't remember what all I changed):
src/util/io.rs
Changed VerifiedFile::new() to accept a ParseOptions argument.
Changed VerifiedFile::new_from_path() similarly.
src/tag/tag_ext.rs
Changed the VerifiedFile::new() call during tag saving to pass:
write_options.parse_options
src/tag/tag_type.rs
Same propagation of write_options.parse_options through:
save_to()
remove_from()
remove_from_path()
src/flac/mod.rs
Changed the VerifiedFile::new() call in the FLAC writer to pass:
write_options.parse_options
I started off investigating this through my use of the bliss-analyser project.
I can try a diff between the Lofty source and my local files at some point. As you can probably tell I am not a Rust programmer and just always curious as to how to get something working...
Regards,
Mitch
Summary
Lofty's VerifiedFile probe doesn't receive the caller's WriteOptions.parse_options, so it silently reverted to the 1,024-byte default set in ParseOptions::DEFAULT_MAX_JUNK_BYTES. The passing of WriteOptions.parse_options to VerifiedFile::new() would allow flexibility of file compatibility. Same as the #1 in [https://github.com//issues/668] which was closed, but only the second issue might have been done?
Expected behavior
Successful addition of new tag data.
Assets
If you would like a test file I can e-mail it to you.
Activity
Serial-ATA commentedon Sep 6, 2026
oops, yeah #668 was only partially finished