Fix integer overflow and divide-by-zero

Bug: 35763994
Test: ran CTS with and without fix
Change-Id: If835e97ce578d4fa567e33e349e48fb7b2559e0e
(cherry picked from commit 8538a603ef992e75f29336499cb783f3ec19f18c)

status_t NuMediaExtractor::updateDurationAndBitrate() {
 if (mImpl->countTracks() > kMaxTrackCount) {
 return ERROR_UNSUPPORTED;
 }

    mTotalBitrate = 0ll;
    mDurationUs = -1ll;

 for (size_t i = 0; i < mImpl->countTracks(); ++i) {
        sp<MetaData> meta = mImpl->getTrackMetaData(i);
 if (meta == NULL) {
            ALOGW("no metadata for track %zu", i);
 continue;
 }

 int32_t bitrate;
 if (!meta->findInt32(kKeyBitRate, &bitrate)) {
 const char *mime;
            CHECK(meta->findCString(kKeyMIMEType, &mime));
            ALOGV("track of type '%s' does not publish bitrate", mime);

            mTotalBitrate = -1ll;
 } else if (mTotalBitrate >= 0ll) {
            mTotalBitrate += bitrate;
 }

 int64_t durationUs;
 if (meta->findInt64(kKeyDuration, &durationUs)
 && durationUs > mDurationUs) {
            mDurationUs = durationUs;
 }
 }
 return OK;
}

status_t NuMediaExtractor::updateDurationAndBitrate() {
 if (mImpl->countTracks() > kMaxTrackCount) {
 return ERROR_UNSUPPORTED;
 }

    mTotalBitrate = 0ll;
    mDurationUs = -1ll;

 for (size_t i = 0; i < mImpl->countTracks(); ++i) {
        sp<MetaData> meta = mImpl->getTrackMetaData(i);
 if (meta == NULL) {
            ALOGW("no metadata for track %zu", i);
 continue;
 }

 int32_t bitrate;
 if (!meta->findInt32(kKeyBitRate, &bitrate)) {
 const char *mime;
            CHECK(meta->findCString(kKeyMIMEType, &mime));
            ALOGV("track of type '%s' does not publish bitrate", mime);

            mTotalBitrate = -1ll;
 } else if (mTotalBitrate >= 0ll) {
            mTotalBitrate += bitrate;
 }

 int64_t durationUs;
 if (meta->findInt64(kKeyDuration, &durationUs)
 && durationUs > mDurationUs) {
            mDurationUs = durationUs;
 }
 }
 return OK;
}
