Fix BPM validation checks to prevent invalid value access#15793
Fix BPM validation checks to prevent invalid value access#15793shbhmexe wants to merge 4 commits into
Conversation
Add missing BPM validity checks before calling value() method to prevent debug assertions and potential undefined behavior when BPM is invalid. Signed-off-by: shbhmexe <shubhushukla586@gmail.com>
|
Thank you for this fix. As a first-time contributor we need you to sign the Mixxx Contributor Agreement and comment here when you have done so. It gives us permission to distribute your contribution under the GPL v2 or later license and the Apple Mac App Store. It is also helpful for us to have contact information for contributors in case we may need it in the future. I think all branches are affected. Can you rebase it to 2.5 This way it will become outo merged to all branches. |
|
The Fixme comments have been introduced here: |
daschuer
left a comment
There was a problem hiding this comment.
The code looks good, I have added comments for improvement.
| // First validate all BPM values | ||
| if (!minBpm.isValid() || !centerBpm.isValid() || !maxBpm.isValid()) { | ||
| // If any BPM is invalid, return the centerBpm as-is | ||
| return centerBpm; |
There was a problem hiding this comment.
These comments are redundant, because they are explaining C++ not the intention. How about this:
| // First validate all BPM values | |
| if (!minBpm.isValid() || !centerBpm.isValid() || !maxBpm.isValid()) { | |
| // If any BPM is invalid, return the centerBpm as-is | |
| return centerBpm; | |
| // If any BPM is invalid, return the centerBpm as-is to avoid | |
| // unexpected results in the following calculations | |
| if (!minBpm.isValid() || !centerBpm.isValid() || !maxBpm.isValid()) { | |
| return centerBpm; |
There was a problem hiding this comment.
Can you also add here a check:
https://github.com/daschuer/mixxx/blob/8720b7595fbbecd62d20c89bf66ff500adce5408/src/track/beatutils.cpp#L310
else we will have div by zero below.
There was a problem hiding this comment.
Can you add this check as well to avoid division by zero?
| // Validate BPM before using it | ||
| if (!bpm.isValid()) { | ||
| // If BPM is invalid, return firstBeat without adjustment |
There was a problem hiding this comment.
adjustPhase() is called here with a isValid() check before. Now we have it inside which allows us to move it before the call here:
https://github.com/daschuer/mixxx/blob/8720b7595fbbecd62d20c89bf66ff500adce5408/src/track/beatfactory.cpp#L83
The comment has also no value:
| // Validate BPM before using it | |
| if (!bpm.isValid()) { | |
| // If BPM is invalid, return firstBeat without adjustment | |
| if (!bpm.isValid()) { |
There was a problem hiding this comment.
The change at the cited code position has not been fixed. Can you have a look?
Co-authored-by: Daniel Schürmann <daschuer@mixxx.org>
Co-authored-by: Daniel Schürmann <daschuer@mixxx.org>
Co-authored-by: Daniel Schürmann <daschuer@mixxx.org>
|
All changes as requested have been completed. Please let me know if there are any other requests in this PR. |
|
@daschuer have all your change requests been addresed? Is the rebase the only thing missing? |
|
I can confirm that @shbhmexe has signed the contributor agreement. Thank you. |
|
This PR is marked as stale because it has been open 90 days with no activity. |
Fixes 3 critical issues where
mixxx::Bpm::value()was accessed withoutisValid()checks, risking debug assertions and undefined behavior.Changes
roundBpmWithinRangeto return early if inputs are invalid.adjustPhaseto prevent division by zero/invalid BPM.adjustBeatsBpmbefore value access.Verification
value()calls are guarded byisValid().