diff options
author | Dongwon Kang <dwkang@google.com> | 2017-11-20 17:55:24 -0800 |
---|---|---|
committer | Ivan Kutepov <its.kutepov@gmail.com> | 2018-02-08 02:44:11 +0300 |
commit | 7eb61bf0d945e1e93da91468c6ae39532071427d (patch) | |
tree | 55dcc688440b0dde07a4389bcb9ac0f0c2cd0974 | |
parent | d43b790fe4e45c0a0ab598e169672af0904dc0d3 (diff) | |
download | frameworks_av-7eb61bf0d945e1e93da91468c6ae39532071427d.tar.gz frameworks_av-7eb61bf0d945e1e93da91468c6ae39532071427d.tar.bz2 frameworks_av-7eb61bf0d945e1e93da91468c6ae39532071427d.zip |
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 fed57366c58aa69ad8f1df5191d6bf48e58d86a8)
CVE-2017-13241
5 files changed, 36 insertions, 8 deletions
diff --git a/media/libstagefright/codecs/avcenc/SoftAVCEnc.cpp b/media/libstagefright/codecs/avcenc/SoftAVCEnc.cpp index 07d12453b0..8a8d84fe16 100644 --- a/media/libstagefright/codecs/avcenc/SoftAVCEnc.cpp +++ b/media/libstagefright/codecs/avcenc/SoftAVCEnc.cpp @@ -1134,6 +1134,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) { diff --git a/media/libstagefright/codecs/m4v_h263/enc/SoftMPEG4Encoder.cpp b/media/libstagefright/codecs/m4v_h263/enc/SoftMPEG4Encoder.cpp index 800238685e..fe98438a59 100644 --- a/media/libstagefright/codecs/m4v_h263/enc/SoftMPEG4Encoder.cpp +++ b/media/libstagefright/codecs/m4v_h263/enc/SoftMPEG4Encoder.cpp @@ -442,6 +442,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 = diff --git a/media/libstagefright/codecs/on2/enc/SoftVPXEncoder.cpp b/media/libstagefright/codecs/on2/enc/SoftVPXEncoder.cpp index 26c0fca559..fabe2e9654 100644 --- a/media/libstagefright/codecs/on2/enc/SoftVPXEncoder.cpp +++ b/media/libstagefright/codecs/on2/enc/SoftVPXEncoder.cpp @@ -726,6 +726,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; @@ -741,14 +748,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); diff --git a/media/libstagefright/include/SoftVideoEncoderOMXComponent.h b/media/libstagefright/include/SoftVideoEncoderOMXComponent.h index b43635deba..02555a2f34 100644 --- a/media/libstagefright/include/SoftVideoEncoderOMXComponent.h +++ b/media/libstagefright/include/SoftVideoEncoderOMXComponent.h @@ -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, diff --git a/media/libstagefright/omx/SoftVideoEncoderOMXComponent.cpp b/media/libstagefright/omx/SoftVideoEncoderOMXComponent.cpp index dc3ed393fa..a8d54bcdb6 100644 --- a/media/libstagefright/omx/SoftVideoEncoderOMXComponent.cpp +++ b/media/libstagefright/omx/SoftVideoEncoderOMXComponent.cpp @@ -637,4 +637,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 |