-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
ID3v2: Ignore frames with bad IDs while reading #214
ID3v2: Ignore frames with bad IDs while reading #214
Conversation
f501dc5
to
b448b9b
Compare
b448b9b
to
d29c7b4
Compare
CI fails again due to unrelated rustfmt errors. |
src/id3/v2/frame/header.rs
Outdated
Ok(id) => id, | ||
Err(err) => match parse_mode { | ||
ParsingMode::Strict => return Err(err), | ||
ParsingMode::BestAttempt | ParsingMode::Relaxed => return Ok(None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok(None)
is currently used to indicate that we encountered padding or the reader is exhausted. This won't only ignore the bad frame ID, but stop reading the tag entirely.
I think errors should continue to be thrown from parse_*_header
, and handled once in Frame::read
. That'd simplify things a bit, since the match on parse_mode
appears 3 times in this file.
From there, you can return Ok((None, false))
from Frame::read
to indicate that there are more frames to come after the failure:
Lines 50 to 56 in f1e8ab6
match Frame::read(reader, header.version, parse_mode)? { | |
// No frame content found, and we can expect there are no more frames | |
(None, true) => break, | |
(Some(f), false) => drop(tag.insert(f)), | |
// No frame content found, but we can expect more frames | |
_ => {}, | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then Option
is the wrong choice here and very confusing. It needs to be replaced by a dedicated type that reveals the semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely. This isn't the only place where Option
s and bool
s are being misused. It's something I'll have to look into eventually.
match parse_mode { | ||
ParsingMode::Strict => return Err(err), | ||
ParsingMode::BestAttempt | ParsingMode::Relaxed => { | ||
// Skip this frame and continue reading |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test for this, and just realized that the frame will not actually be skipped over.
There would need to be a way to get the size
out of the header even if there's an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Code could be improved later to avoid the mutable reference param. Not urgent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming of the ParsedFrame
variant is more appropriate now, because the skipping actually happens later.
Thanks! I'll move Clippy/rustfmt to stable, the failures are annoying. |
Follow-up of #212.