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

Commit cd0677fd authored by Andy Hung's avatar Andy Hung Committed by android-build-merger
Browse files

Merge "AudioFlinger: Check framecount overflow when creating track" into...

Merge "AudioFlinger: Check framecount overflow when creating track" into lmp-dev am: 51a3483e am: 5dc0e88c am: 6d4b5fc3 am: 5562d704 am: 3fb4149e am: 78ec3327 am: 9262496a am: 12b5b3b0 am: dfecfdb2 am: 3c93457c
am: a4475163

Change-Id: I63259b73f31fbd64d79a5cfb426767f2f18e0904
parents ba2f1aa0 a4475163
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -110,9 +110,24 @@ AudioFlinger::ThreadBase::TrackBase::TrackBase(
    mUid = clientUid;

    // ALOGD("Creating track with %d buffers @ %d bytes", bufferCount, bufferSize);

    size_t bufferSize = buffer == NULL ? roundup(frameCount) : frameCount;
    // check overflow when computing bufferSize due to multiplication by mFrameSize.
    if (bufferSize < frameCount  // roundup rounds down for values above UINT_MAX / 2
            || mFrameSize == 0   // format needs to be correct
            || bufferSize > SIZE_MAX / mFrameSize) {
        android_errorWriteLog(0x534e4554, "34749571");
        return;
    }
    bufferSize *= mFrameSize;

    size_t size = sizeof(audio_track_cblk_t);
    size_t bufferSize = (buffer == NULL ? roundup(frameCount) : frameCount) * mFrameSize;
    if (buffer == NULL && alloc == ALLOC_CBLK) {
        // check overflow when computing allocation size for streaming tracks.
        if (size > SIZE_MAX - bufferSize) {
            android_errorWriteLog(0x534e4554, "34749571");
            return;
        }
        size += bufferSize;
    }