Check for overflow of crypto size

Bug: 111603051
Test: CTS
Change-Id: Ib5b1802b9b35769a25c16e2b977308cf7a810606
(cherry picked from commit d1fd02761236b35a336434367131f71bef7405c9)

uint8_t* AMediaCodec_getOutputBuffer(AMediaCodec *mData, size_t idx, size_t *out_size) {
 if (mData->mAsyncNotify != NULL) {
        sp<MediaCodecBuffer> abuf;
 if (mData->mCodec->getOutputBuffer(idx, &abuf) != 0) {
 return NULL;
 }

 if (out_size != NULL) {
 *out_size = abuf->capacity();
 }
 return abuf->data();
 }

    android::Vector<android::sp<android::MediaCodecBuffer> > abufs;
 if (mData->mCodec->getOutputBuffers(&abufs) == 0) {
 size_t n = abufs.size();
 if (idx >= n) {
            ALOGE("buffer index %zu out of range", idx);
 return NULL;
 }
 if (out_size != NULL) {
 *out_size = abufs[idx]->capacity();
 }
 return abufs[idx]->data();
 }
    ALOGE("couldn't get output buffers");
 return NULL;
}

uint8_t* AMediaCodec_getOutputBuffer(AMediaCodec *mData, size_t idx, size_t *out_size) {
 if (mData->mAsyncNotify != NULL) {
        sp<MediaCodecBuffer> abuf;
 if (mData->mCodec->getOutputBuffer(idx, &abuf) != 0) {
 return NULL;
 }

 if (out_size != NULL) {
 *out_size = abuf->capacity();
 }
 return abuf->data();
 }

    android::Vector<android::sp<android::MediaCodecBuffer> > abufs;
 if (mData->mCodec->getOutputBuffers(&abufs) == 0) {
 size_t n = abufs.size();
 if (idx >= n) {
            ALOGE("buffer index %zu out of range", idx);
 return NULL;
 }
 if (out_size != NULL) {
 *out_size = abufs[idx]->capacity();
 }
 return abufs[idx]->data();
 }
    ALOGE("couldn't get output buffers");
 return NULL;
}
