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

Commit fb41e97c authored by Dongwon Kang's avatar Dongwon Kang Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE: Apply input buffer validation also to AVC and MPEG4 encoders" into lmp-mr1-dev

parents c558af3f daed7a60
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -583,15 +583,17 @@ void SoftAVCEncoder::onQueueFilled(OMX_U32 /* portIndex */) {
                videoInput.height = align(mHeight, 16);
                videoInput.pitch = align(mWidth, 16);
                videoInput.coding_timestamp = (inHeader->nTimeStamp + 500) / 1000;  // in ms
                const uint8_t *inputData = NULL;
                if (mInputDataIsMeta) {
                    if (inHeader->nFilledLen != 8) {
                        ALOGE("MetaData buffer is wrong size! "
                                "(got %u bytes, expected 8)", inHeader->nFilledLen);

                OMX_ERRORTYPE error = validateInputBuffer(inHeader);
                if (error != OMX_ErrorNone) {
                    ALOGE("b/69065651");
                    android_errorWriteLog(0x534e4554, "69065651");
                    mSignalledError = true;
                        notify(OMX_EventError, OMX_ErrorUndefined, 0, 0);
                    notify(OMX_EventError, error, 0, 0);
                    return;
                }
                const uint8_t *inputData = NULL;
                if (mInputDataIsMeta) {
                    inputData =
                        extractGraphicBuffer(
                                mInputFrameData, (mWidth * mHeight * 3) >> 1,
+8 −7
Original line number Diff line number Diff line
@@ -442,15 +442,16 @@ void SoftMPEG4Encoder::onQueueFilled(OMX_U32 /* portIndex */) {
        }

        if (inHeader->nFilledLen > 0) {
            const uint8_t *inputData = NULL;
            if (mInputDataIsMeta) {
                if (inHeader->nFilledLen != 8) {
                    ALOGE("MetaData buffer is wrong size! "
                            "(got %u bytes, expected 8)", inHeader->nFilledLen);
            OMX_ERRORTYPE error = validateInputBuffer(inHeader);
            if (error != OMX_ErrorNone) {
                ALOGE("b/69065651");
                android_errorWriteLog(0x534e4554, "69065651");
                mSignalledError = true;
                    notify(OMX_EventError, OMX_ErrorUndefined, 0, 0);
                notify(OMX_EventError, error, 0, 0);
                return;
            }
            const uint8_t *inputData = NULL;
            if (mInputDataIsMeta) {
                inputData =
                    extractGraphicBuffer(
                            mInputFrameData, (mWidth * mHeight * 3) >> 1,
+7 −8
Original line number Diff line number Diff line
@@ -725,6 +725,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;

@@ -740,14 +747,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);
+2 −0
Original line number Diff line number Diff line
@@ -68,6 +68,8 @@ protected:

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

    OMX_ERRORTYPE validateInputBuffer(const OMX_BUFFERHEADERTYPE *inputBufferHeader);

    enum {
        kInputPortIndex = 0,
        kOutputPortIndex = 1,
+11 −0
Original line number Diff line number Diff line
@@ -638,4 +638,15 @@ OMX_ERRORTYPE SoftVideoEncoderOMXComponent::getExtensionIndex(
    return SimpleSoftOMXComponent::getExtensionIndex(name, index);
}

OMX_ERRORTYPE SoftVideoEncoderOMXComponent::validateInputBuffer(
        const OMX_BUFFERHEADERTYPE *inputBufferHeader) {
    size_t frameSize = mInputDataIsMeta ? 8 : 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