Merge "Catch nullptr possibilities in MediaExtractor jni code" into udc-dev

This commit is contained in:
Treehugger Robot
2023-04-12 12:19:43 +00:00
committed by Android (Google) Code Review

View File

@@ -196,6 +196,15 @@ status_t JMediaExtractor::readSampleData(
dstSize = (size_t) env->GetDirectBufferCapacity(byteBuf);
}
// unlikely, but GetByteArrayElements() can fail
if (dst == nullptr) {
ALOGE("no buffer into which to read the data");
if (byteArray != NULL) {
env->ReleaseByteArrayElements(byteArray, (jbyte *)dst, 0);
}
return -ENOMEM;
}
if (dstSize < offset) {
if (byteArray != NULL) {
env->ReleaseByteArrayElements(byteArray, (jbyte *)dst, 0);
@@ -204,8 +213,10 @@ status_t JMediaExtractor::readSampleData(
return -ERANGE;
}
// passes in the backing memory to use, so it doesn't fail
sp<ABuffer> buffer = new ABuffer((char *)dst + offset, dstSize - offset);
buffer->setRange(0, 0); // mark it empty
status_t err = mImpl->readSampleData(buffer);
if (byteArray != NULL) {