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

Commit f4aeab2b authored by Andy Hung's avatar Andy Hung
Browse files

Track: Check buffer size of static tracks

Merged-In: Ia7edd9a802905214a27961dbcec6352f6ef98f73
Test: Native POC
Bug: 38340117
Change-Id: I633caf563d3607dbe4b9be10be1687efce33469c
parent ea83248d
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -437,6 +437,21 @@ AudioFlinger::PlaybackThread::Track::Track(
        mAudioTrackServerProxy = new AudioTrackServerProxy(mCblk, mBuffer, frameCount,
                mFrameSize, !isExternalTrack(), sampleRate);
    } else {
        // Is the shared buffer of sufficient size?
        // (frameCount * mFrameSize) is <= SIZE_MAX, checked in TrackBase.
        if (sharedBuffer->size() < frameCount * mFrameSize) {
            // Workaround: clear out mCblk to indicate track hasn't been properly created.
            mCblk->~audio_track_cblk_t();   // destroy our shared-structure.
            if (mClient == 0) {
                free(mCblk);
            }
            mCblk = NULL;

            mSharedBuffer.clear(); // release shared buffer early
            android_errorWriteLog(0x534e4554, "38340117");
            return;
        }

        mAudioTrackServerProxy = new StaticAudioTrackServerProxy(mCblk, mBuffer, frameCount,
                mFrameSize);
    }