Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(content): Decode IPLS/TIPL/TMCL with odd value count gracefully #154

Merged
merged 2 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions src/stream/frame/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,21 @@ impl<'a> Decoder<'a> {
Some(result)
}
(Some(_), None) => {
// This can only happen if there is an uneven number of elements.
*last_string = None;
Some(Err(Error::new(
ErrorKind::Parsing,
"uneven number of IPLS strings",
)))
// This can only happen if there is an uneven number of elements. For
// compatibility, we assume that the missing value is an empty string instead of
// erroring out and failing to parse the entire tag.
//
// This is in line with what the Python mutagen library does. See this issue for
// details:
// - <https://github.com/polyfloyd/rust-id3/issues/147>
let first = last_string.take().expect("option must be some");
let result = first.map(|involvement| {
Some(InvolvedPeopleListItem {
involvement,
involvee: String::new(),
})
});
Some(result)
}
(None, None) => None,
})
Expand Down Expand Up @@ -1711,7 +1720,28 @@ mod tests {
data.extend(bytes_for_encoding("other involvement", *encoding).into_iter());
data.extend(delim_for_encoding(*encoding).into_iter());
// involveee missing here
assert!(decode(frame_id, version, &data[..]).is_err());

let content = frame::InvolvedPeopleList {
items: vec![
InvolvedPeopleListItem {
involvement: "involvement".to_string(),
involvee: "involvee".to_string(),
},
InvolvedPeopleListItem {
involvement: "other involvement".to_string(),
// Assume empty string if value is missing
involvee: "".to_string(),
},
],
};
assert_eq!(
*decode(frame_id, version, &data[..])
.unwrap()
.0
.involved_people_list()
.unwrap(),
content
);
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,14 @@ mod tests {
let _tag = Tag::read_from_path("testdata/github-issue-91.id3").unwrap();
}

#[test]
fn github_issue_147() {
// Tag contains a broken IPLS frame with an odd value count. We need to handle this
// gracefully without failing to parse the entire tag, because these issue is apparently
// widespread.
let _tag = Tag::read_from_path("testdata/github-issue-147.id3").unwrap();
}

#[test]
fn aiff_read_and_write() {
// Copy
Expand Down
Binary file added testdata/github-issue-147.id3
Binary file not shown.