diff options
Diffstat (limited to 'media/libstagefright/codecs/m4v_h263/enc/src/mp4enc_api.cpp')
-rw-r--r-- | media/libstagefright/codecs/m4v_h263/enc/src/mp4enc_api.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/media/libstagefright/codecs/m4v_h263/enc/src/mp4enc_api.cpp b/media/libstagefright/codecs/m4v_h263/enc/src/mp4enc_api.cpp index 5ea0de4..6c4510e 100644 --- a/media/libstagefright/codecs/m4v_h263/enc/src/mp4enc_api.cpp +++ b/media/libstagefright/codecs/m4v_h263/enc/src/mp4enc_api.cpp @@ -619,6 +619,10 @@ OSCL_EXPORT_REF Bool PVInitVideoEncoder(VideoEncControls *encoderControl, Vid max = temp_w * temp_h; max_width = ((temp_w + 15) >> 4) << 4; max_height = ((temp_h + 15) >> 4) << 4; + if (((uint64_t)max_width * max_height) > (uint64_t)INT32_MAX + || temp_w > INT32_MAX - 15 || temp_h > INT32_MAX - 15) { + goto CLEAN_UP; + } nTotalMB = ((max_width * max_height) >> 8); } @@ -663,6 +667,9 @@ OSCL_EXPORT_REF Bool PVInitVideoEncoder(VideoEncControls *encoderControl, Vid /* Allocating motion vector space and interpolation memory*/ + if ((size_t)nTotalMB > SIZE_MAX / sizeof(MOT *)) { + goto CLEAN_UP; + } video->mot = (MOT **)M4VENC_MALLOC(sizeof(MOT *) * nTotalMB); if (video->mot == NULL) goto CLEAN_UP; @@ -685,11 +692,17 @@ OSCL_EXPORT_REF Bool PVInitVideoEncoder(VideoEncControls *encoderControl, Vid /* so that compilers can generate faster code to indexing the */ /* data inside (by using << instead of *). 04/14/2000. */ /* 5/29/01, use decoder lib ACDC prediction memory scheme. */ + if ((size_t)nTotalMB > SIZE_MAX / sizeof(typeDCStore)) { + goto CLEAN_UP; + } video->predDC = (typeDCStore *) M4VENC_MALLOC(nTotalMB * sizeof(typeDCStore)); if (video->predDC == NULL) goto CLEAN_UP; if (!video->encParams->H263_Enabled) { + if ((size_t)((max_width >> 4) + 1) > SIZE_MAX / sizeof(typeDCACStore)) { + goto CLEAN_UP; + } video->predDCAC_col = (typeDCACStore *) M4VENC_MALLOC(((max_width >> 4) + 1) * sizeof(typeDCACStore)); if (video->predDCAC_col == NULL) goto CLEAN_UP; @@ -697,6 +710,9 @@ OSCL_EXPORT_REF Bool PVInitVideoEncoder(VideoEncControls *encoderControl, Vid /* the rest will be used for storing horizontal (row) AC coefficients */ video->predDCAC_row = video->predDCAC_col + 1; /* ACDC */ + if ((size_t)nTotalMB > SIZE_MAX / sizeof(Int)) { + goto CLEAN_UP; + } video->acPredFlag = (Int *) M4VENC_MALLOC(nTotalMB * sizeof(Int)); /* Memory for acPredFlag */ if (video->acPredFlag == NULL) goto CLEAN_UP; } @@ -750,8 +766,15 @@ OSCL_EXPORT_REF Bool PVInitVideoEncoder(VideoEncControls *encoderControl, Vid offset = (pitch << 4) + 16; max_height += 32; } + if (((uint64_t)pitch * max_height) > (uint64_t)INT32_MAX) { + goto CLEAN_UP; + } size = pitch * max_height; + if (size > INT32_MAX - (size >> 1) + || (size_t)(size + (size >> 1)) > SIZE_MAX / sizeof(PIXEL)) { + goto CLEAN_UP; + } video->currVop->yChan = (PIXEL *)M4VENC_MALLOC(sizeof(PIXEL) * (size + (size >> 1))); /* Memory for currVop Y */ if (video->currVop->yChan == NULL) goto CLEAN_UP; video->currVop->uChan = video->currVop->yChan + size;/* Memory for currVop U */ @@ -850,6 +873,9 @@ OSCL_EXPORT_REF Bool PVInitVideoEncoder(VideoEncControls *encoderControl, Vid /* /// End /////////////////////////////////////// */ + if ((size_t)nLayers > SIZE_MAX / sizeof(Vol *)) { + goto CLEAN_UP; + } video->vol = (Vol **)M4VENC_MALLOC(nLayers * sizeof(Vol *)); /* Memory for VOL pointers */ /* Memory allocation and Initialization of Vols and writing of headers */ |