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

ID3v2: Ignore frames with bad IDs while reading #214

Merged
merged 4 commits into from
Jul 3, 2023

Conversation

uklotzde
Copy link
Contributor

@uklotzde uklotzde commented Jul 2, 2023

Follow-up of #212.

@uklotzde uklotzde force-pushed the id3v2-frame-id-parse-mode branch 2 times, most recently from f501dc5 to b448b9b Compare July 2, 2023 11:37
@uklotzde
Copy link
Contributor Author

uklotzde commented Jul 2, 2023

CI fails again due to unrelated rustfmt errors.

@uklotzde uklotzde marked this pull request as ready for review July 2, 2023 23:32
Ok(id) => id,
Err(err) => match parse_mode {
ParsingMode::Strict => return Err(err),
ParsingMode::BestAttempt | ParsingMode::Relaxed => return Ok(None),
Copy link
Owner

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:

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
_ => {},
}

Copy link
Contributor Author

@uklotzde uklotzde Jul 3, 2023

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.

Copy link
Owner

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 Options and bools 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
Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@uklotzde uklotzde Jul 3, 2023

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.

@Serial-ATA
Copy link
Owner

Thanks!

I'll move Clippy/rustfmt to stable, the failures are annoying.

@Serial-ATA Serial-ATA merged commit 97a53c0 into Serial-ATA:main Jul 3, 2023
9 of 12 checks passed
Serial-ATA added a commit that referenced this pull request Jul 3, 2023
Serial-ATA added a commit that referenced this pull request Jul 4, 2023
Serial-ATA added a commit that referenced this pull request Jul 5, 2023
@uklotzde uklotzde deleted the id3v2-frame-id-parse-mode branch July 22, 2023 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants