| Index: core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/j2k.c
|
| diff --git a/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/j2k.c b/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/j2k.c
|
| index bf411efca5bda7069e8c829301c44233ec90ea7c..d16d8883b9c03c5b010e7265a149370e6216dcbd 100644
|
| --- a/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/j2k.c
|
| +++ b/core/src/fxcodec/fx_libopenjpeg/libopenjpeg20/j2k.c
|
| @@ -4136,6 +4136,10 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
|
| if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) {
|
| p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index =
|
| (opj_tp_index_t*)opj_calloc(l_num_parts, sizeof(opj_tp_index_t));
|
| + if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) {
|
| + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n");
|
| + return OPJ_FALSE;
|
| + }
|
| }
|
| else {
|
| opj_tp_index_t *new_tp_index = (opj_tp_index_t *) opj_realloc(
|
| @@ -4143,7 +4147,7 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
|
| if (! new_tp_index) {
|
| opj_free(p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index);
|
| p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = NULL;
|
| - opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n");
|
| + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n");
|
| return OPJ_FALSE;
|
| }
|
| p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
|
| @@ -4157,6 +4161,11 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
|
| p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index =
|
| (opj_tp_index_t*)opj_calloc( p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps,
|
| sizeof(opj_tp_index_t));
|
| + if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) {
|
| + p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = 0;
|
| + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n");
|
| + return OPJ_FALSE;
|
| + }
|
| }
|
|
|
| if ( l_current_part >= p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps ){
|
| @@ -4169,7 +4178,7 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
|
| opj_free(p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index);
|
| p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = NULL;
|
| p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = 0;
|
| - opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n");
|
| + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n");
|
| return OPJ_FALSE;
|
| }
|
| p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
|
| @@ -6153,7 +6162,7 @@ OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_
|
| return OPJ_TRUE;
|
| }
|
|
|
| -void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
| +OPJ_BOOL opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
| opj_cparameters_t *parameters,
|
| opj_image_t *image,
|
| opj_event_mgr_t * p_manager)
|
| @@ -6162,7 +6171,7 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
| opj_cp_t *cp = 00;
|
|
|
| if(!p_j2k || !parameters || ! image) {
|
| - return;
|
| + return OPJ_FALSE;
|
| }
|
|
|
| /* keep a link to cp so that we can destroy it later in j2k_destroy_compress */
|
| @@ -6194,6 +6203,10 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
| if (parameters->cp_fixed_alloc && parameters->cp_matrice) {
|
| size_t array_size = (size_t)parameters->tcp_numlayers * (size_t)parameters->numresolution * 3 * sizeof(OPJ_INT32);
|
| cp->m_specific_param.m_enc.m_matrice = (OPJ_INT32 *) opj_malloc(array_size);
|
| + if (!cp->m_specific_param.m_enc.m_matrice) {
|
| + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate copy of user encoding parameters matrix \n");
|
| + return OPJ_FALSE;
|
| + }
|
| memcpy(cp->m_specific_param.m_enc.m_matrice, parameters->cp_matrice, array_size);
|
| }
|
|
|
| @@ -6207,11 +6220,36 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
|
|
| /* comment string */
|
| if(parameters->cp_comment) {
|
| - cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1);
|
| - if(cp->comment) {
|
| - strcpy(cp->comment, parameters->cp_comment);
|
| - }
|
| - }
|
| + cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1U);
|
| + if(!cp->comment) {
|
| + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate copy of comment string\n");
|
| + return OPJ_FALSE;
|
| + }
|
| + strcpy(cp->comment, parameters->cp_comment);
|
| + } else {
|
| + /* Create default comment for codestream */
|
| + const char comment[] = "Created by OpenJPEG version ";
|
| + const size_t clen = strlen(comment);
|
| + const char *version = opj_version();
|
| +
|
| + /* UniPG>> */
|
| +#ifdef USE_JPWL
|
| + cp->comment = (char*)opj_malloc(clen+strlen(version)+11);
|
| + if(!cp->comment) {
|
| + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate comment string\n");
|
| + return OPJ_FALSE;
|
| + }
|
| + sprintf(cp->comment,"%s%s with JPWL", comment, version);
|
| +#else
|
| + cp->comment = (char*)opj_malloc(clen+strlen(version)+1);
|
| + if(!cp->comment) {
|
| + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate comment string\n");
|
| + return OPJ_FALSE;
|
| + }
|
| + sprintf(cp->comment,"%s%s", comment, version);
|
| +#endif
|
| + /* <<UniPG */
|
| + }
|
|
|
| /*
|
| calculate other encoding parameters
|
| @@ -6289,6 +6327,10 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
| /* initialize the mutiple tiles */
|
| /* ---------------------------- */
|
| cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
|
| + if (!cp->tcps) {
|
| + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate tile coding parameters\n");
|
| + return OPJ_FALSE;
|
| + }
|
| if (parameters->numpocs) {
|
| /* initialisation of POC */
|
| opj_j2k_check_poc_val(parameters->POC,parameters->numpocs, (OPJ_UINT32)parameters->numresolution, image->numcomps, (OPJ_UINT32)parameters->tcp_numlayers, p_manager);
|
| @@ -6346,24 +6388,54 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
| }
|
|
|
| tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t));
|
| -
|
| + if (!tcp->tccps) {
|
| + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate tile component coding parameters\n");
|
| + return OPJ_FALSE;
|
| + }
|
| if (parameters->mct_data) {
|
|
|
| OPJ_UINT32 lMctSize = image->numcomps * image->numcomps * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
|
| OPJ_FLOAT32 * lTmpBuf = (OPJ_FLOAT32*)opj_malloc(lMctSize);
|
| OPJ_INT32 * l_dc_shift = (OPJ_INT32 *) ((OPJ_BYTE *) parameters->mct_data + lMctSize);
|
|
|
| + if (!lTmpBuf) {
|
| + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate temp buffer\n");
|
| + return OPJ_FALSE;
|
| + }
|
| +
|
| tcp->mct = 2;
|
| tcp->m_mct_coding_matrix = (OPJ_FLOAT32*)opj_malloc(lMctSize);
|
| + if (! tcp->m_mct_coding_matrix) {
|
| + opj_free(lTmpBuf);
|
| + lTmpBuf = NULL;
|
| + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate encoder MCT coding matrix \n");
|
| + return OPJ_FALSE;
|
| + }
|
| memcpy(tcp->m_mct_coding_matrix,parameters->mct_data,lMctSize);
|
| memcpy(lTmpBuf,parameters->mct_data,lMctSize);
|
|
|
| tcp->m_mct_decoding_matrix = (OPJ_FLOAT32*)opj_malloc(lMctSize);
|
| - assert(opj_matrix_inversion_f(lTmpBuf,(tcp->m_mct_decoding_matrix),image->numcomps));
|
| + if (! tcp->m_mct_decoding_matrix) {
|
| + opj_free(lTmpBuf);
|
| + lTmpBuf = NULL;
|
| + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate encoder MCT decoding matrix \n");
|
| + return OPJ_FALSE;
|
| + }
|
| + if(opj_matrix_inversion_f(lTmpBuf,(tcp->m_mct_decoding_matrix),image->numcomps) == OPJ_FALSE) {
|
| + opj_free(lTmpBuf);
|
| + lTmpBuf = NULL;
|
| + opj_event_msg(p_manager, EVT_ERROR, "Failed to inverse encoder MCT decoding matrix \n");
|
| + return OPJ_FALSE;
|
| + }
|
|
|
| tcp->mct_norms = (OPJ_FLOAT64*)
|
| opj_malloc(image->numcomps * sizeof(OPJ_FLOAT64));
|
| -
|
| + if (! tcp->mct_norms) {
|
| + opj_free(lTmpBuf);
|
| + lTmpBuf = NULL;
|
| + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate encoder MCT norms \n");
|
| + return OPJ_FALSE;
|
| + }
|
| opj_calculate_norms(tcp->mct_norms,image->numcomps,tcp->m_mct_decoding_matrix);
|
| opj_free(lTmpBuf);
|
|
|
| @@ -6372,7 +6444,11 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
| tccp->m_dc_level_shift = l_dc_shift[i];
|
| }
|
|
|
| - opj_j2k_setup_mct_encoding(tcp,image);
|
| + if (opj_j2k_setup_mct_encoding(tcp,image) == OPJ_FALSE) {
|
| + /* free will be handled by opj_j2k_destroy */
|
| + opj_event_msg(p_manager, EVT_ERROR, "Failed to setup j2k mct encoding\n");
|
| + return OPJ_FALSE;
|
| + }
|
| }
|
| else {
|
| for (i = 0; i < image->numcomps; i++) {
|
| @@ -6461,6 +6537,7 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
| opj_free(parameters->mct_data);
|
| parameters->mct_data = 00;
|
| }
|
| + return OPJ_TRUE;
|
| }
|
|
|
| static OPJ_BOOL opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len)
|
| @@ -8164,16 +8241,11 @@ opj_j2k_t* opj_j2k_create_decompress(void)
|
|
|
| /* codestream index creation */
|
| l_j2k->cstr_index = opj_j2k_create_cstr_index();
|
| -
|
| - /*(opj_codestream_index_t*) opj_malloc(sizeof(opj_codestream_index_t));
|
| if (!l_j2k->cstr_index){
|
| opj_j2k_destroy(l_j2k);
|
| - return NULL;
|
| + return 00;
|
| }
|
|
|
| - l_j2k->cstr_index->marker = (opj_marker_info_t*) opj_malloc(100 * sizeof(opj_marker_info_t));
|
| -*/
|
| -
|
| /* validation list creation */
|
| l_j2k->m_validation_list = opj_procedure_list_create();
|
| if (! l_j2k->m_validation_list) {
|
| @@ -9588,6 +9660,10 @@ OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k,
|
| assert(p_manager != 00);
|
|
|
| p_j2k->m_private_image = opj_image_create0();
|
| + if (! p_j2k->m_private_image) {
|
| + opj_event_msg(p_manager, EVT_ERROR, "Failed to allocate image header." );
|
| + return OPJ_FALSE;
|
| + }
|
| opj_copy_image_header(p_image, p_j2k->m_private_image);
|
|
|
| /* TODO_MSD: Find a better way */
|
|
|