Fix potential overflow related issues spotted by LGTM code analysis (#1402)

This commit is contained in:
Eric Harvey 2022-01-18 15:55:10 -05:00 committed by GitHub
parent d87fd9279a
commit 241e9e8efe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 7 deletions

View File

@ -1677,7 +1677,7 @@ static OPJ_BOOL opj_j2k_check_poc_val(const opj_poc_t *p_pocs,
assert(p_nb_pocs > 0); assert(p_nb_pocs > 0);
packet_array = (OPJ_UINT32*) opj_calloc(step_l * p_num_layers, packet_array = (OPJ_UINT32*) opj_calloc((size_t)step_l * p_num_layers,
sizeof(OPJ_UINT32)); sizeof(OPJ_UINT32));
if (packet_array == 00) { if (packet_array == 00) {
opj_event_msg(p_manager, EVT_ERROR, opj_event_msg(p_manager, EVT_ERROR,

View File

@ -1136,9 +1136,9 @@ static OPJ_BOOL opj_jp2_apply_pclr(opj_image_t *image,
} }
max = image->numcomps; max = image->numcomps;
for (i = 0; i < max; ++i) { for (j = 0; j < max; ++j) {
if (old_comps[i].data) { if (old_comps[j].data) {
opj_image_data_free(old_comps[i].data); opj_image_data_free(old_comps[j].data);
} }
} }

View File

@ -457,7 +457,7 @@ void opj_calculate_norms(OPJ_FLOAT64 * pNorms,
for (j = 0; j < pNbComps; ++j) { for (j = 0; j < pNbComps; ++j) {
lCurrentValue = lMatrix[lIndex]; lCurrentValue = lMatrix[lIndex];
lIndex += pNbComps; lIndex += pNbComps;
lNorms[i] += lCurrentValue * lCurrentValue; lNorms[i] += (OPJ_FLOAT64) lCurrentValue * lCurrentValue;
} }
lNorms[i] = sqrt(lNorms[i]); lNorms[i] = sqrt(lNorms[i]);
} }

View File

@ -69,7 +69,7 @@ opj_sparse_array_int32_t* opj_sparse_array_int32_create(OPJ_UINT32 width,
return NULL; return NULL;
} }
sa->data_blocks = (OPJ_INT32**) opj_calloc(sizeof(OPJ_INT32*), sa->data_blocks = (OPJ_INT32**) opj_calloc(sizeof(OPJ_INT32*),
sa->block_count_hor * sa->block_count_ver); (size_t) sa->block_count_hor * sa->block_count_ver);
if (sa->data_blocks == NULL) { if (sa->data_blocks == NULL) {
opj_free(sa); opj_free(sa);
return NULL; return NULL;
@ -235,7 +235,7 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write(
} else { } else {
if (src_block == NULL) { if (src_block == NULL) {
src_block = (OPJ_INT32*) opj_calloc(1, src_block = (OPJ_INT32*) opj_calloc(1,
sa->block_width * sa->block_height * sizeof(OPJ_INT32)); (size_t) sa->block_width * sa->block_height * sizeof(OPJ_INT32));
if (src_block == NULL) { if (src_block == NULL) {
return OPJ_FALSE; return OPJ_FALSE;
} }