diff options
Diffstat (limited to 'openjpeg/src/lib/openjp2')
-rw-r--r-- | openjpeg/src/lib/openjp2/CMakeLists.txt | 3 | ||||
-rw-r--r-- | openjpeg/src/lib/openjp2/bench_dwt.c | 2 | ||||
-rw-r--r-- | openjpeg/src/lib/openjp2/dwt.c | 11 | ||||
-rw-r--r-- | openjpeg/src/lib/openjp2/image.c | 4 | ||||
-rw-r--r-- | openjpeg/src/lib/openjp2/j2k.c | 44 | ||||
-rw-r--r-- | openjpeg/src/lib/openjp2/jp2.c | 9 | ||||
-rw-r--r-- | openjpeg/src/lib/openjp2/openjpeg.h | 10 | ||||
-rw-r--r-- | openjpeg/src/lib/openjp2/opj_intmath.h | 2 | ||||
-rw-r--r-- | openjpeg/src/lib/openjp2/pi.c | 19 | ||||
-rw-r--r-- | openjpeg/src/lib/openjp2/t1.c | 17 | ||||
-rw-r--r-- | openjpeg/src/lib/openjp2/t2.c | 18 | ||||
-rw-r--r-- | openjpeg/src/lib/openjp2/tcd.c | 26 | ||||
-rw-r--r-- | openjpeg/src/lib/openjp2/thread.c | 4 |
13 files changed, 117 insertions, 52 deletions
diff --git a/openjpeg/src/lib/openjp2/CMakeLists.txt b/openjpeg/src/lib/openjp2/CMakeLists.txt index 0b452038..b2714858 100644 --- a/openjpeg/src/lib/openjp2/CMakeLists.txt +++ b/openjpeg/src/lib/openjp2/CMakeLists.txt @@ -99,6 +99,7 @@ else() set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME} openjp2_static) else() add_library(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS}) + set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME}) endif() endif() @@ -106,7 +107,7 @@ if(UNIX) target_link_libraries(${OPENJPEG_LIBRARY_NAME} m) endif() set_target_properties(${OPENJPEG_LIBRARY_NAME} PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES}) -if(${CMAKE_VERSION} VERSION_GREATER "2.8.11") +if(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.12") target_compile_options(${OPENJPEG_LIBRARY_NAME} PRIVATE ${OPENJP2_COMPILE_OPTIONS}) endif() diff --git a/openjpeg/src/lib/openjp2/bench_dwt.c b/openjpeg/src/lib/openjp2/bench_dwt.c index 103b681a..8cb64d06 100644 --- a/openjpeg/src/lib/openjp2/bench_dwt.c +++ b/openjpeg/src/lib/openjp2/bench_dwt.c @@ -257,7 +257,7 @@ int main(int argc, char** argv) size_t idx; size_t nValues = (size_t)(tilec.x1 - tilec.x0) * (size_t)(tilec.y1 - tilec.y0); - for (idx = 0; i < (OPJ_INT32)nValues; i++) { + for (idx = 0; idx < nValues; idx++) { if (tilec.data[idx] != getValue((OPJ_UINT32)idx)) { printf("Difference found at idx = %u\n", (OPJ_UINT32)idx); exit(1); diff --git a/openjpeg/src/lib/openjp2/dwt.c b/openjpeg/src/lib/openjp2/dwt.c index 5b98d2b3..5930d1c7 100644 --- a/openjpeg/src/lib/openjp2/dwt.c +++ b/openjpeg/src/lib/openjp2/dwt.c @@ -974,7 +974,7 @@ static void opj_idwt53_v(const opj_dwt_t *dwt, #if (defined(__SSE2__) || defined(__AVX2__)) if (len > 1 && nb_cols == PARALLEL_COLS_53) { /* Same as below general case, except that thanks to SSE2/AVX2 */ - /* we can efficently process 8/16 columns in parallel */ + /* we can efficiently process 8/16 columns in parallel */ opj_idwt53_v_cas0_mcols_SSE2_OR_AVX2(dwt->mem, sn, len, tiledp_col, stride); return; } @@ -1017,7 +1017,7 @@ static void opj_idwt53_v(const opj_dwt_t *dwt, #if (defined(__SSE2__) || defined(__AVX2__)) if (len > 2 && nb_cols == PARALLEL_COLS_53) { /* Same as below general case, except that thanks to SSE2/AVX2 */ - /* we can efficently process 8/16 columns in parallel */ + /* we can efficiently process 8/16 columns in parallel */ opj_idwt53_v_cas1_mcols_SSE2_OR_AVX2(dwt->mem, sn, len, tiledp_col, stride); return; } @@ -2041,7 +2041,7 @@ static OPJ_BOOL opj_dwt_decode_partial_tile( tr_hl_x0 = (OPJ_UINT32)tr->bands[0].x0; tr_lh_y0 = (OPJ_UINT32)tr->bands[1].y0; - /* Substract the origin of the bands for this tile, to the subwindow */ + /* Subtract the origin of the bands for this tile, to the subwindow */ /* of interest band coordinates, so as to get them relative to the */ /* tile */ win_ll_x0 = opj_uint_subs(win_ll_x0, tr_ll_x0); @@ -2696,17 +2696,20 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, /* overflow check */ if (l_data_size > (SIZE_MAX - 5U)) { /* FIXME event manager error callback */ + opj_sparse_array_int32_free(sa); return OPJ_FALSE; } l_data_size += 5U; /* overflow check */ if (l_data_size > (SIZE_MAX / sizeof(opj_v4_t))) { /* FIXME event manager error callback */ + opj_sparse_array_int32_free(sa); return OPJ_FALSE; } h.wavelet = (opj_v4_t*) opj_aligned_malloc(l_data_size * sizeof(opj_v4_t)); if (!h.wavelet) { /* FIXME event manager error callback */ + opj_sparse_array_int32_free(sa); return OPJ_FALSE; } v.wavelet = h.wavelet; @@ -2759,7 +2762,7 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, tr_hl_x0 = (OPJ_UINT32)tr->bands[0].x0; tr_lh_y0 = (OPJ_UINT32)tr->bands[1].y0; - /* Substract the origin of the bands for this tile, to the subwindow */ + /* Subtract the origin of the bands for this tile, to the subwindow */ /* of interest band coordinates, so as to get them relative to the */ /* tile */ win_ll_x0 = opj_uint_subs(win_ll_x0, tr_ll_x0); diff --git a/openjpeg/src/lib/openjp2/image.c b/openjpeg/src/lib/openjp2/image.c index 13bcb8e4..fe373905 100644 --- a/openjpeg/src/lib/openjp2/image.c +++ b/openjpeg/src/lib/openjp2/image.c @@ -48,8 +48,8 @@ opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, image->color_space = clrspc; image->numcomps = numcmpts; /* allocate memory for the per-component information */ - image->comps = (opj_image_comp_t*)opj_calloc(1, - image->numcomps * sizeof(opj_image_comp_t)); + image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, + sizeof(opj_image_comp_t)); if (!image->comps) { /* TODO replace with event manager, breaks API */ /* fprintf(stderr,"Unable to allocate memory for image.\n"); */ diff --git a/openjpeg/src/lib/openjp2/j2k.c b/openjpeg/src/lib/openjp2/j2k.c index 25e0a348..4a4b3494 100644 --- a/openjpeg/src/lib/openjp2/j2k.c +++ b/openjpeg/src/lib/openjp2/j2k.c @@ -508,7 +508,7 @@ static OPJ_BOOL opj_j2k_write_cod(opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager); /** - * Reads a COD marker (Coding Styke defaults) + * Reads a COD marker (Coding style defaults) * @param p_header_data the data contained in the COD box. * @param p_j2k the jpeg2000 codec. * @param p_header_size the size of the data contained in the COD marker. @@ -1925,7 +1925,8 @@ static OPJ_BOOL opj_j2k_read_soc(opj_j2k_t *p_j2k, /* FIXME move it in a index structure included in p_j2k*/ p_j2k->cstr_index->main_head_start = opj_stream_tell(p_stream) - 2; - opj_event_msg(p_manager, EVT_INFO, "Start to read j2k main header (%d).\n", + opj_event_msg(p_manager, EVT_INFO, + "Start to read j2k main header (%" PRId64 ").\n", p_j2k->cstr_index->main_head_start); /* Add the marker to the codestream index*/ @@ -2625,7 +2626,7 @@ static OPJ_BOOL opj_j2k_write_cod(opj_j2k_t *p_j2k, } /** - * Reads a COD marker (Coding Styke defaults) + * Reads a COD marker (Coding style defaults) * @param p_header_data the data contained in the COD box. * @param p_j2k the jpeg2000 codec. * @param p_header_size the size of the data contained in the COD marker. @@ -2657,12 +2658,17 @@ static OPJ_BOOL opj_j2k_read_cod(opj_j2k_t *p_j2k, &l_cp->tcps[p_j2k->m_current_tile_number] : p_j2k->m_specific_param.m_decoder.m_default_tcp; +#if 0 + /* This check was added per https://github.com/uclouvain/openjpeg/commit/daed8cc9195555e101ab708a501af2dfe6d5e001 */ + /* but this is no longer necessary to handle issue476.jp2 */ + /* and this actually cause issues on legit files. See https://github.com/uclouvain/openjpeg/issues/1043 */ /* Only one COD per tile */ if (l_tcp->cod) { opj_event_msg(p_manager, EVT_ERROR, "COD marker already read. No more than one COD marker per tile.\n"); return OPJ_FALSE; } +#endif l_tcp->cod = 1; /* Make sure room is sufficient */ @@ -3502,7 +3508,7 @@ static OPJ_BOOL opj_j2k_read_poc(opj_j2k_t *p_j2k, l_old_poc_nb = l_tcp->POC ? l_tcp->numpocs + 1 : 0; l_current_poc_nb += l_old_poc_nb; - if (l_current_poc_nb >= sizeof(l_tcp->pocs) / sizeof(l_tcp->pocs[0])) { + if (l_current_poc_nb >= J2K_MAX_POCS) { opj_event_msg(p_manager, EVT_ERROR, "Too many POCs %d\n", l_current_poc_nb); return OPJ_FALSE; } @@ -4089,7 +4095,12 @@ static OPJ_BOOL opj_j2k_merge_ppt(opj_tcp_t *p_tcp, opj_event_mgr_t * p_manager) /* preconditions */ assert(p_tcp != 00); assert(p_manager != 00); - assert(p_tcp->ppt_buffer == NULL); + + if (p_tcp->ppt_buffer != NULL) { + opj_event_msg(p_manager, EVT_ERROR, + "opj_j2k_merge_ppt() has already been called\n"); + return OPJ_FALSE; + } if (p_tcp->ppt == 0U) { return OPJ_TRUE; @@ -6419,7 +6430,9 @@ void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters) OPJ_BOOL opj_j2k_set_threads(opj_j2k_t *j2k, OPJ_UINT32 num_threads) { - if (opj_has_thread_support()) { + /* Currently we pass the thread-pool to the tcd, so we cannot re-set it */ + /* afterwards */ + if (opj_has_thread_support() && j2k->m_tcd == NULL) { opj_thread_pool_destroy(j2k->m_tp); j2k->m_tp = NULL; if (num_threads <= (OPJ_UINT32)INT_MAX) { @@ -6434,9 +6447,8 @@ OPJ_BOOL opj_j2k_set_threads(opj_j2k_t *j2k, OPJ_UINT32 num_threads) return OPJ_FALSE; } -static int opj_j2k_get_default_thread_count(void) +static int opj_j2k_get_default_thread_count() { -#if defined(MUTEX_win32) || defined(MUTEX_pthread) const char* num_threads_str = getenv("OPJ_NUM_THREADS"); int num_cpus; int num_threads; @@ -6458,9 +6470,6 @@ static int opj_j2k_get_default_thread_count(void) num_threads = 2 * num_cpus; } return num_threads; -#else - return 0; -#endif } /* ----------------------------------------------------------------------- */ @@ -8842,7 +8851,10 @@ OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t * p_j2k, /* Current marker is the EOC marker ?*/ if (l_current_marker == J2K_MS_EOC) { - p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_EOC; + if (p_j2k->m_specific_param.m_decoder.m_state != J2K_STATE_EOC) { + p_j2k->m_current_tile_number = 0; + p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_EOC; + } } /* FIXME DOC ???*/ @@ -9224,6 +9236,14 @@ static OPJ_BOOL opj_j2k_update_image_dimensions(opj_image_t* p_image, l_img_comp = p_image->comps; for (it_comp = 0; it_comp < p_image->numcomps; ++it_comp) { OPJ_INT32 l_h, l_w; + if (p_image->x0 > (OPJ_UINT32)INT_MAX || + p_image->y0 > (OPJ_UINT32)INT_MAX || + p_image->x1 > (OPJ_UINT32)INT_MAX || + p_image->y1 > (OPJ_UINT32)INT_MAX) { + opj_event_msg(p_manager, EVT_ERROR, + "Image coordinates above INT_MAX are not supported\n"); + return OPJ_FALSE; + } l_img_comp->x0 = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)p_image->x0, (OPJ_INT32)l_img_comp->dx); diff --git a/openjpeg/src/lib/openjp2/jp2.c b/openjpeg/src/lib/openjp2/jp2.c index c79ea731..4402ffe3 100644 --- a/openjpeg/src/lib/openjp2/jp2.c +++ b/openjpeg/src/lib/openjp2/jp2.c @@ -1005,7 +1005,7 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, if (!pcol_usage[i]) { is_sane = 0U; opj_event_msg(p_manager, EVT_WARNING, - "Component mapping seems wrong. Trying to correct.\n", i); + "Component mapping seems wrong. Trying to correct.\n"); break; } } @@ -1079,7 +1079,7 @@ static OPJ_BOOL opj_jp2_apply_pclr(opj_image_t *image, /* Palette mapping: */ new_comps[i].data = (OPJ_INT32*) - opj_image_data_alloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(OPJ_INT32)); + opj_image_data_alloc(sizeof(OPJ_INT32) * old_comps[cmp].w * old_comps[cmp].h); if (!new_comps[i].data) { while (i > 0) { -- i; @@ -1106,7 +1106,6 @@ static OPJ_BOOL opj_jp2_apply_pclr(opj_image_t *image, /* Direct use: */ if (cmap[i].mtyp == 0) { - assert(cmp == 0); dst = new_comps[i].data; assert(dst); for (j = 0; j < max; ++j) { @@ -1194,8 +1193,8 @@ static OPJ_BOOL opj_jp2_read_pclr(opj_jp2_t *jp2, return OPJ_FALSE; } - entries = (OPJ_UINT32*) opj_malloc((size_t)nr_channels * nr_entries * sizeof( - OPJ_UINT32)); + entries = (OPJ_UINT32*) opj_malloc(sizeof(OPJ_UINT32) * nr_channels * + nr_entries); if (!entries) { return OPJ_FALSE; } diff --git a/openjpeg/src/lib/openjp2/openjpeg.h b/openjpeg/src/lib/openjp2/openjpeg.h index f36286eb..53a0e10c 100644 --- a/openjpeg/src/lib/openjp2/openjpeg.h +++ b/openjpeg/src/lib/openjp2/openjpeg.h @@ -548,7 +548,7 @@ typedef struct opj_dparameters { /** Verbose mode */ OPJ_BOOL m_verbose; - /** tile number ot the decoded tile*/ + /** tile number of the decoded tile */ OPJ_UINT32 tile_index; /** Nb of tile to decode */ OPJ_UINT32 nb_tile_to_decode; @@ -1178,7 +1178,8 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function); /** - * Sets the given function to be used as a seek function, the stream is then seekable. + * Sets the given function to be used as a seek function, the stream is then seekable, + * using SEEK_SET behavior. * @param p_stream the stream to modify * @param p_function the function to use a skip function. */ @@ -1313,6 +1314,9 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec, * number, or "ALL_CPUS". If OPJ_NUM_THREADS is set and this function is called, * this function will override the behaviour of the environment variable. * + * Currently this function must be called after opj_setup_decoder() and + * before opj_read_header(). + * * Note: currently only has effect on the decompressor. * * @param p_codec decompressor handler @@ -1381,7 +1385,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_components(opj_codec_t *p_codec, * performance improvements when reading an image by chunks. * * @param p_codec the jpeg2000 codec. - * @param p_image the decoded image previously setted by opj_read_header + * @param p_image the decoded image previously set by opj_read_header * @param p_start_x the left position of the rectangle to decode (in image coordinates). * @param p_end_x the right position of the rectangle to decode (in image coordinates). * @param p_start_y the up position of the rectangle to decode (in image coordinates). diff --git a/openjpeg/src/lib/openjp2/opj_intmath.h b/openjpeg/src/lib/openjp2/opj_intmath.h index ad135976..754b5512 100644 --- a/openjpeg/src/lib/openjp2/opj_intmath.h +++ b/openjpeg/src/lib/openjp2/opj_intmath.h @@ -170,7 +170,7 @@ Divide an integer and round upwards static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) { assert(b); - return (a + b - 1) / b; + return (OPJ_UINT32)(((OPJ_UINT64)a + b - 1) / b); } /** diff --git a/openjpeg/src/lib/openjp2/pi.c b/openjpeg/src/lib/openjp2/pi.c index 91642ee4..4a6ed68e 100644 --- a/openjpeg/src/lib/openjp2/pi.c +++ b/openjpeg/src/lib/openjp2/pi.c @@ -748,6 +748,9 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image, /* position in x and y of tile */ OPJ_UINT32 p, q; + /* non-corrected (in regard to image offset) tile offset */ + OPJ_UINT32 l_tx0, l_ty0; + /* preconditions */ assert(p_cp != 00); assert(p_image != 00); @@ -763,14 +766,14 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image, q = p_tileno / p_cp->tw; /* find extent of tile */ - *p_tx0 = opj_int_max((OPJ_INT32)(p_cp->tx0 + p * p_cp->tdx), - (OPJ_INT32)p_image->x0); - *p_tx1 = opj_int_min((OPJ_INT32)(p_cp->tx0 + (p + 1) * p_cp->tdx), - (OPJ_INT32)p_image->x1); - *p_ty0 = opj_int_max((OPJ_INT32)(p_cp->ty0 + q * p_cp->tdy), - (OPJ_INT32)p_image->y0); - *p_ty1 = opj_int_min((OPJ_INT32)(p_cp->ty0 + (q + 1) * p_cp->tdy), - (OPJ_INT32)p_image->y1); + l_tx0 = p_cp->tx0 + p * + p_cp->tdx; /* can't be greater than p_image->x1 so won't overflow */ + *p_tx0 = (OPJ_INT32)opj_uint_max(l_tx0, p_image->x0); + *p_tx1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_tx0, p_cp->tdx), p_image->x1); + l_ty0 = p_cp->ty0 + q * + p_cp->tdy; /* can't be greater than p_image->y1 so won't overflow */ + *p_ty0 = (OPJ_INT32)opj_uint_max(l_ty0, p_image->y0); + *p_ty1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_ty0, p_cp->tdy), p_image->y1); /* max precision is 0 (can only grow) */ *p_max_prec = 0; diff --git a/openjpeg/src/lib/openjp2/t1.c b/openjpeg/src/lib/openjp2/t1.c index 76744380..f6f76711 100644 --- a/openjpeg/src/lib/openjp2/t1.c +++ b/openjpeg/src/lib/openjp2/t1.c @@ -1618,8 +1618,8 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) cblk_w = (OPJ_UINT32)(cblk->x1 - cblk->x0); cblk_h = (OPJ_UINT32)(cblk->y1 - cblk->y0); - cblk->decoded_data = (OPJ_INT32*)opj_aligned_malloc(cblk_w * cblk_h * sizeof( - OPJ_INT32)); + cblk->decoded_data = (OPJ_INT32*)opj_aligned_malloc(sizeof(OPJ_INT32) * + cblk_w * cblk_h); if (cblk->decoded_data == NULL) { if (job->p_manager_mutex) { opj_mutex_lock(job->p_manager_mutex); @@ -1634,7 +1634,7 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) return; } /* Zero-init required */ - memset(cblk->decoded_data, 0, cblk_w * cblk_h * sizeof(OPJ_INT32)); + memset(cblk->decoded_data, 0, sizeof(OPJ_INT32) * cblk_w * cblk_h); } else if (cblk->decoded_data) { /* Not sure if that code path can happen, but better be */ /* safe than sorry */ @@ -2168,9 +2168,18 @@ OPJ_BOOL opj_t1_encode_cblks(opj_t1_t *t1, t1->data = tiledp; t1->data_stride = tile_w; if (tccp->qmfbid == 1) { + /* Do multiplication on unsigned type, even if the + * underlying type is signed, to avoid potential + * int overflow on large value (the output will be + * incorrect in such situation, but whatever...) + * This assumes complement-to-2 signed integer + * representation + * Fixes https://github.com/uclouvain/openjpeg/issues/1053 + */ + OPJ_UINT32* OPJ_RESTRICT tiledp_u = (OPJ_UINT32*) tiledp; for (j = 0; j < cblk_h; ++j) { for (i = 0; i < cblk_w; ++i) { - tiledp[tileIndex] *= (1 << T1_NMSEDEC_FRACBITS); + tiledp_u[tileIndex] <<= T1_NMSEDEC_FRACBITS; tileIndex++; } tileIndex += tileLineAdvance; diff --git a/openjpeg/src/lib/openjp2/t2.c b/openjpeg/src/lib/openjp2/t2.c index c7a3ceed..9825118c 100644 --- a/openjpeg/src/lib/openjp2/t2.c +++ b/openjpeg/src/lib/openjp2/t2.c @@ -667,7 +667,11 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno, opj_tcd_resolution_t *res = &tilec->resolutions[resno]; opj_bio_t *bio = 00; /* BIO component */ +#ifdef ENABLE_EMPTY_PACKET_OPTIMIZATION OPJ_BOOL packet_empty = OPJ_TRUE; +#else + OPJ_BOOL packet_empty = OPJ_FALSE; +#endif /* <SOP 0xff91> */ if (tcp->csty & J2K_CP_CSTY_SOP) { @@ -728,6 +732,11 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno, } opj_bio_init_enc(bio, c, length); +#ifdef ENABLE_EMPTY_PACKET_OPTIMIZATION + /* WARNING: this code branch is disabled, since it has been reported that */ + /* such packets cause decoding issues with cinema J2K hardware */ + /* decoders: https://groups.google.com/forum/#!topic/openjpeg/M7M_fLX_Bco */ + /* Check if the packet is empty */ /* Note: we could also skip that step and always write a packet header */ band = res->bands; @@ -755,10 +764,9 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno, break; } } - +#endif opj_bio_write(bio, packet_empty ? 0 : 1, 1); /* Empty header bit */ - /* Writing Packet header */ band = res->bands; for (bandno = 0; !packet_empty && @@ -1222,12 +1230,6 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, l_included, l_cblk->segs[l_segno].numnewpasses, l_increment, l_cblk->segs[l_segno].newlen); - /* testcase 1802.pdf.SIGSEGV.36e.894 */ - if (l_cblk->segs[l_segno].newlen > *l_modified_length_ptr) { - opj_bio_destroy(l_bio); - return OPJ_FALSE; - } - n -= (OPJ_INT32)l_cblk->segs[l_segno].numnewpasses; if (n > 0) { ++l_segno; diff --git a/openjpeg/src/lib/openjp2/tcd.c b/openjpeg/src/lib/openjp2/tcd.c index 1dd15405..647991c7 100644 --- a/openjpeg/src/lib/openjp2/tcd.c +++ b/openjpeg/src/lib/openjp2/tcd.c @@ -905,8 +905,24 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ l_tl_prc_x_start = opj_int_floordivpow2(l_res->x0, (OPJ_INT32)l_pdx) << l_pdx; l_tl_prc_y_start = opj_int_floordivpow2(l_res->y0, (OPJ_INT32)l_pdy) << l_pdy; - l_br_prc_x_end = opj_int_ceildivpow2(l_res->x1, (OPJ_INT32)l_pdx) << l_pdx; - l_br_prc_y_end = opj_int_ceildivpow2(l_res->y1, (OPJ_INT32)l_pdy) << l_pdy; + { + OPJ_UINT32 tmp = ((OPJ_UINT32)opj_int_ceildivpow2(l_res->x1, + (OPJ_INT32)l_pdx)) << l_pdx; + if (tmp > (OPJ_UINT32)INT_MAX) { + opj_event_msg(manager, EVT_ERROR, "Integer overflow\n"); + return OPJ_FALSE; + } + l_br_prc_x_end = (OPJ_INT32)tmp; + } + { + OPJ_UINT32 tmp = ((OPJ_UINT32)opj_int_ceildivpow2(l_res->y1, + (OPJ_INT32)l_pdy)) << l_pdy; + if (tmp > (OPJ_UINT32)INT_MAX) { + opj_event_msg(manager, EVT_ERROR, "Integer overflow\n"); + return OPJ_FALSE; + } + l_br_prc_y_end = (OPJ_INT32)tmp; + } /*fprintf(stderr, "\t\t\tprc_x_start=%d, prc_y_start=%d, br_prc_x_end=%d, br_prc_y_end=%d \n", l_tl_prc_x_start, l_tl_prc_y_start, l_br_prc_x_end ,l_br_prc_y_end );*/ l_res->pw = (l_res->x0 == l_res->x1) ? 0U : (OPJ_UINT32)(( @@ -1067,6 +1083,12 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, l_nb_code_blocks = l_current_precinct->cw * l_current_precinct->ch; /*fprintf(stderr, "\t\t\t\t precinct_cw = %d x recinct_ch = %d\n",l_current_precinct->cw, l_current_precinct->ch); */ + if ((((OPJ_UINT32) - 1) / (OPJ_UINT32)sizeof_block) < + l_nb_code_blocks) { + opj_event_msg(manager, EVT_ERROR, + "Size of code block data exceeds system limits\n"); + return OPJ_FALSE; + } l_nb_code_blocks_size = l_nb_code_blocks * (OPJ_UINT32)sizeof_block; if (!l_current_precinct->cblks.blocks && (l_nb_code_blocks > 0U)) { diff --git a/openjpeg/src/lib/openjp2/thread.c b/openjpeg/src/lib/openjp2/thread.c index af33c2c8..f2fca2ee 100644 --- a/openjpeg/src/lib/openjp2/thread.c +++ b/openjpeg/src/lib/openjp2/thread.c @@ -723,6 +723,8 @@ static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads) tp->worker_threads[i].thread = opj_thread_create(opj_worker_thread_function, &(tp->worker_threads[i])); if (tp->worker_threads[i].thread == NULL) { + opj_mutex_destroy(tp->worker_threads[i].mutex); + opj_cond_destroy(tp->worker_threads[i].cond); tp->worker_threads_count = i; bRet = OPJ_FALSE; break; @@ -732,7 +734,7 @@ static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads) /* Wait all threads to be started */ /* printf("waiting for all threads to be started\n"); */ opj_mutex_lock(tp->mutex); - while (tp->waiting_worker_thread_count < num_threads) { + while (tp->waiting_worker_thread_count < tp->worker_threads_count) { opj_cond_wait(tp->cond, tp->mutex); } opj_mutex_unlock(tp->mutex); |