Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 73f21de1 authored by Ray Essick's avatar Ray Essick
Browse files

Avoid overflows in MediaClock calculations

Bug: 205409934
Test: clusterFuzz
Change-Id: I184cbe61e3134685d1b70353895de35ab66f0f5a
parent 8eb8981e
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -110,8 +110,12 @@ void MediaClock::updateAnchor(
    if (mAnchorTimeRealUs != -1) {
        int64_t oldNowMediaUs =
            mAnchorTimeMediaUs + (nowUs - mAnchorTimeRealUs) * (double)mPlaybackRate;
        if (nowMediaUs < oldNowMediaUs + kAnchorFluctuationAllowedUs
                && nowMediaUs > oldNowMediaUs - kAnchorFluctuationAllowedUs) {
        // earlier, we ensured that the anchor times are non-negative and the
        // math to calculate the now/oldNow times stays non-negative.
        // by casting into uint64_t, we gain headroom to avoid any overflows at the upper end
        // when adding the fluctuation allowance.
        if ((uint64_t)nowMediaUs < (uint64_t)oldNowMediaUs + kAnchorFluctuationAllowedUs
                && (uint64_t)nowMediaUs + kAnchorFluctuationAllowedUs > (uint64_t)oldNowMediaUs) {
            return;
        }
    }