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: Fix debug assertion after importing a bpm value of 0 #4154

Merged
merged 1 commit into from
Jul 28, 2021
Merged
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
68 changes: 35 additions & 33 deletions src/track/taglib/trackmetadata_id3v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,45 +795,47 @@ void importTrackMetadataFromTag(
if (!bpmFrames.isEmpty()) {
parseBpm(pTrackMetadata,
firstNonEmptyFrameToQString(bpmFrames));
double bpmValue = pTrackMetadata->getTrackInfo().getBpm().value();
// Some software use (or used) to write decimated values without comma,
// so the number reads as 1352 or 14525 when it is 135.2 or 145.25
if (bpmValue < Bpm::kValueMin || bpmValue > 1000 * Bpm::kValueMax) {
// Considered out of range, don't try to adjust it
kLogger.warning()
<< "Ignoring invalid bpm value"
<< bpmValue;
bpmValue = Bpm::kValueUndefined;
} else {
double bpmValueOriginal = bpmValue;
DEBUG_ASSERT(Bpm::kValueUndefined <= Bpm::kValueMax);
bool adjusted = false;
while (bpmValue > Bpm::kValueMax) {
double bpmValueAdjusted = bpmValue / 10;
if (bpmValueAdjusted < bpmValue) {
bpmValue = bpmValueAdjusted;
adjusted = true;
continue;
}
// Ensure that the loop always terminates even for invalid
// values like Inf and NaN!
if (pTrackMetadata->getTrackInfo().getBpm().isValid()) {
double bpmValue = pTrackMetadata->getTrackInfo().getBpm().value();
// Some software use (or used) to write decimated values without comma,
// so the number reads as 1352 or 14525 when it is 135.2 or 145.25
if (bpmValue < Bpm::kValueMin || bpmValue > 1000 * Bpm::kValueMax) {
// Considered out of range, don't try to adjust it
kLogger.warning()
<< "Ignoring invalid bpm value"
<< bpmValueOriginal;
<< bpmValue;
bpmValue = Bpm::kValueUndefined;
break;
} else {
double bpmValueOriginal = bpmValue;
DEBUG_ASSERT(Bpm::kValueUndefined <= Bpm::kValueMax);
bool adjusted = false;
while (bpmValue > Bpm::kValueMax) {
double bpmValueAdjusted = bpmValue / 10;
if (bpmValueAdjusted < bpmValue) {
bpmValue = bpmValueAdjusted;
adjusted = true;
continue;
}
// Ensure that the loop always terminates even for invalid
// values like Inf and NaN!
kLogger.warning()
<< "Ignoring invalid bpm value"
<< bpmValueOriginal;
bpmValue = Bpm::kValueUndefined;
break;
}
if (adjusted) {
kLogger.info()
<< "Adjusted bpm value from"
<< bpmValueOriginal
<< "to"
<< bpmValue;
}
}
if (adjusted) {
kLogger.info()
<< "Adjusted bpm value from"
<< bpmValueOriginal
<< "to"
<< bpmValue;
if (bpmValue != Bpm::kValueUndefined) {
pTrackMetadata->refTrackInfo().setBpm(Bpm(bpmValue));
}
}
if (bpmValue != Bpm::kValueUndefined) {
pTrackMetadata->refTrackInfo().setBpm(Bpm(bpmValue));
}
}

const TagLib::ID3v2::FrameList keyFrames(tag.frameListMap()["TKEY"]);
Expand Down