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

Commit 4e091c66 authored by Dongwon Kang's avatar Dongwon Kang Committed by android-build-team Robot
Browse files

Apply input buffer validation also to AVC and MPEG4 encoders

Input buffer validation is existing only on VPX encoders. This patch
applies the checking also to the other sw video encoders.

Bug: 69065651 Bug: 27569635
Test: run poc with and without the patch.
Test: pass post submit media CTS tests after disabling hw encoders.

Merged-In: I1358df64352577fd6d41cd4bfec18be37c98fe6f
Change-Id: I1358df64352577fd6d41cd4bfec18be37c98fe6f
(cherry picked from commit fed57366)
parent 45425ee2
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1170,6 +1170,12 @@ OMX_ERRORTYPE SoftAVC::setEncodeArgs(
    ps_inp_raw_buf->e_color_fmt = mIvVideoColorFormat;
    source = NULL;
    if ((inputBufferHeader != NULL) && inputBufferHeader->nFilledLen) {
        OMX_ERRORTYPE error = validateInputBuffer(inputBufferHeader);
        if (error != OMX_ErrorNone) {
            ALOGE("b/69065651");
            android_errorWriteLog(0x534e4554, "69065651");
            return error;
        }
        source = inputBufferHeader->pBuffer + inputBufferHeader->nOffset;

        if (mInputDataIsMeta) {
+8 −0
Original line number Diff line number Diff line
@@ -434,6 +434,14 @@ void SoftMPEG4Encoder::onQueueFilled(OMX_U32 /* portIndex */) {
        }

        if (inHeader->nFilledLen > 0) {
            OMX_ERRORTYPE error = validateInputBuffer(inHeader);
            if (error != OMX_ErrorNone) {
                ALOGE("b/69065651");
                android_errorWriteLog(0x534e4554, "69065651");
                mSignalledError = true;
                notify(OMX_EventError, error, 0, 0);
                return;
            }
            const uint8_t *inputData = NULL;
            if (mInputDataIsMeta) {
                inputData =
+7 −8
Original line number Diff line number Diff line
@@ -653,6 +653,13 @@ void SoftVPXEncoder::onQueueFilled(OMX_U32 /* portIndex */) {
            return;
        }

        OMX_ERRORTYPE error = validateInputBuffer(inputBufferHeader);
        if (error != OMX_ErrorNone) {
            ALOGE("b/27569635");
            android_errorWriteLog(0x534e4554, "27569635");
            notify(OMX_EventError, error, 0, 0);
            return;
        }
        const uint8_t *source =
            inputBufferHeader->pBuffer + inputBufferHeader->nOffset;

@@ -668,14 +675,6 @@ void SoftVPXEncoder::onQueueFilled(OMX_U32 /* portIndex */) {
                return;
            }
        } else {
            if (inputBufferHeader->nFilledLen < frameSize) {
                android_errorWriteLog(0x534e4554, "27569635");
                notify(OMX_EventError, OMX_ErrorUndefined, 0, 0);
                return;
            } else if (inputBufferHeader->nFilledLen > frameSize) {
                ALOGW("Input buffer contains too many pixels");
            }

            if (mColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) {
                ConvertYUV420SemiPlanarToYUV420Planar(
                        source, mConversionBuffer, mWidth, mHeight);
+13 −0
Original line number Diff line number Diff line
@@ -664,4 +664,17 @@ OMX_ERRORTYPE SoftVideoEncoderOMXComponent::getExtensionIndex(
    return SimpleSoftOMXComponent::getExtensionIndex(name, index);
}

OMX_ERRORTYPE SoftVideoEncoderOMXComponent::validateInputBuffer(
        const OMX_BUFFERHEADERTYPE *inputBufferHeader) {
    size_t frameSize = mInputDataIsMeta ?
            max(sizeof(VideoNativeMetadata), sizeof(VideoGrallocMetadata))
            : mWidth * mHeight * 3 / 2;
    if (inputBufferHeader->nFilledLen < frameSize) {
        return OMX_ErrorUndefined;
    } else if (inputBufferHeader->nFilledLen > frameSize) {
        ALOGW("Input buffer contains more data than expected.");
    }
    return OMX_ErrorNone;
}

}  // namespace android
+2 −0
Original line number Diff line number Diff line
@@ -67,6 +67,8 @@ protected:

    virtual OMX_ERRORTYPE getExtensionIndex(const char *name, OMX_INDEXTYPE *index);

    OMX_ERRORTYPE validateInputBuffer(const OMX_BUFFERHEADERTYPE *inputBufferHeader);

    enum {
        kInputPortIndex = 0,
        kOutputPortIndex = 1,