34
34
35
35
#include " SoftAVCEncoder.h"
36
36
37
+ #ifndef INT32_MAX
38
+ #define INT32_MAX 2147483647
39
+ #endif
40
+
37
41
namespace android {
38
42
39
43
template <class T >
@@ -257,6 +261,10 @@ OMX_ERRORTYPE SoftAVCEncoder::initEncParams() {
257
261
if (mVideoColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) {
258
262
// Color conversion is needed.
259
263
CHECK (mInputFrameData == NULL );
264
+ if (((uint64_t )mVideoWidth * mVideoHeight ) > ((uint64_t )INT32_MAX / 3 )) {
265
+ ALOGE (" Buffer size is too big." );
266
+ return OMX_ErrorUndefined;
267
+ }
260
268
mInputFrameData =
261
269
(uint8_t *) malloc ((mVideoWidth * mVideoHeight * 3 ) >> 1 );
262
270
CHECK (mInputFrameData != NULL );
@@ -278,6 +286,10 @@ OMX_ERRORTYPE SoftAVCEncoder::initEncParams() {
278
286
int32_t nMacroBlocks = ((((mVideoWidth + 15 ) >> 4 ) << 4 ) *
279
287
(((mVideoHeight + 15 ) >> 4 ) << 4 )) >> 8 ;
280
288
CHECK (mSliceGroup == NULL );
289
+ if ((size_t )nMacroBlocks > SIZE_MAX / sizeof (uint32_t )) {
290
+ ALOGE (" requested memory size is too big." );
291
+ return OMX_ErrorUndefined;
292
+ }
281
293
mSliceGroup = (uint32_t *) malloc (sizeof (uint32_t ) * nMacroBlocks);
282
294
CHECK (mSliceGroup != NULL );
283
295
for (int ii = 0 , idx = 0 ; ii < nMacroBlocks; ++ii) {
@@ -698,6 +710,10 @@ OMX_ERRORTYPE SoftAVCEncoder::internalSetParameter(
698
710
if (mStoreMetaDataInBuffers ) {
699
711
mVideoColorFormat == OMX_COLOR_FormatYUV420SemiPlanar;
700
712
if (mInputFrameData == NULL ) {
713
+ if (((uint64_t )mVideoWidth * mVideoHeight ) > ((uint64_t )INT32_MAX / 3 )) {
714
+ ALOGE (" Buffer size is too big." );
715
+ return OMX_ErrorUndefined;
716
+ }
701
717
mInputFrameData =
702
718
(uint8_t *) malloc ((mVideoWidth * mVideoHeight * 3 ) >> 1 );
703
719
}
0 commit comments