Skip to content

Commit c70b5d0

Browse files
Wei Jiaandi34
authored andcommitted
DO NOT MERGE - libstagefright: check requested memory size before allocation for SoftMPEG4Encoder and SoftVPXEncoder.
Bug: 25812794 Change-Id: I96dc74734380d462583f6efa33d09946f9532809 (cherry picked from commit 87f8cbb) (cherry picked from commit 6afc659)
1 parent 0474810 commit c70b5d0

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

media/libstagefright/codecs/m4v_h263/enc/SoftMPEG4Encoder.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333

3434
#include "SoftMPEG4Encoder.h"
3535

36+
#ifndef INT32_MAX
37+
#define INT32_MAX 2147483647
38+
#endif
39+
3640
namespace android {
3741

3842
template<class T>
@@ -149,7 +153,12 @@ OMX_ERRORTYPE SoftMPEG4Encoder::initEncParams() {
149153

150154
if (mVideoColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) {
151155
// Color conversion is needed.
152-
CHECK(mInputFrameData == NULL);
156+
free(mInputFrameData);
157+
mInputFrameData = NULL;
158+
if (((uint64_t)mVideoWidth * mVideoHeight) > ((uint64_t)INT32_MAX / 3)) {
159+
ALOGE("b/25812794, Buffer size is too big.");
160+
return OMX_ErrorBadParameter;
161+
}
153162
mInputFrameData =
154163
(uint8_t *) malloc((mVideoWidth * mVideoHeight * 3 ) >> 1);
155164
CHECK(mInputFrameData != NULL);

media/libstagefright/codecs/on2/enc/SoftVPXEncoder.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#include <media/stagefright/foundation/ADebug.h>
2626
#include <media/stagefright/MediaDefs.h>
2727

28+
#ifndef INT32_MAX
29+
#define INT32_MAX 2147483647
30+
#endif
31+
2832
namespace android {
2933

3034

@@ -300,6 +304,10 @@ status_t SoftVPXEncoder::initEncoder() {
300304

301305
if (mColorFormat == OMX_COLOR_FormatYUV420SemiPlanar || mInputDataIsMeta) {
302306
if (mConversionBuffer == NULL) {
307+
if (((uint64_t)mWidth * mHeight) > ((uint64_t)INT32_MAX / 3)) {
308+
ALOGE("b/25812794, Buffer size is too big.");
309+
return UNKNOWN_ERROR;
310+
}
303311
mConversionBuffer = (uint8_t *)malloc(mWidth * mHeight * 3 / 2);
304312
if (mConversionBuffer == NULL) {
305313
ALOGE("Allocating conversion buffer failed.");

0 commit comments

Comments
 (0)