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

Commit 259fb46d authored by Ben Romberger's avatar Ben Romberger Committed by Wei Jia
Browse files

libmediaplayerservice: Check for a possible divide by 0

Check if variables used in AudioOutput::open()
are 0 before using them as a divisor.
Bug: 123375287
Change-Id: I1c65a80a12eda84d11e7526fe0c730cb10565c36
CRs-Fixed: 2286455
(cherry picked from commit 9e67171a2f4e2b7dc38017789700f629a3885734)
parent 6327ed96
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -1906,10 +1906,16 @@ status_t MediaPlayerService::AudioOutput::open(
        if (AudioSystem::getOutputSamplingRate(&afSampleRate, mStreamType) != NO_ERROR) {
        if (AudioSystem::getOutputSamplingRate(&afSampleRate, mStreamType) != NO_ERROR) {
            return NO_INIT;
            return NO_INIT;
        }
        }
        if (afSampleRate == 0) {
            return NO_INIT;
        }
        const size_t framesPerBuffer =
        const size_t framesPerBuffer =
                (unsigned long long)sampleRate * afFrameCount / afSampleRate;
                (unsigned long long)sampleRate * afFrameCount / afSampleRate;


        if (bufferCount == 0) {
        if (bufferCount == 0) {
            if (framesPerBuffer == 0) {
                return NO_INIT;
            }
            // use suggestedFrameCount
            // use suggestedFrameCount
            bufferCount = (suggestedFrameCount + framesPerBuffer - 1) / framesPerBuffer;
            bufferCount = (suggestedFrameCount + framesPerBuffer - 1) / framesPerBuffer;
        }
        }