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

Commit 1ef49b87 authored by Ray Essick's avatar Ray Essick
Browse files

Catch nullptr possibilities in MediaExtractor jni code

Detect and gracefully fail some missed cases where a null pointer can
occur in the MediaExtractor code.

Bug: 277614674
Test: CtsMediaExtractorTestCases w/debug messages
Change-Id: I4acb6dbbcf42391194555559ee7bd2612c776ece
parent 13067e72
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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) {