From: Antonin Descampe Date: Tue, 8 Aug 2017 23:51:54 +0000 (-0700) Subject: Merge pull request #975 from szukw000/changes-for-afl-tests X-Git-Tag: v2.2.0~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0394f8d0f1c981e0bc587beddc14d1fb0b265b1b;p=openjpeg Merge pull request #975 from szukw000/changes-for-afl-tests Catch images broken by AFL --- 0394f8d0f1c981e0bc587beddc14d1fb0b265b1b diff --cc src/lib/openjp2/j2k.c index 3737655b,8daf9be8..5a169e18 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@@ -8735,21 -8739,17 +8769,22 @@@ OPJ_BOOL opj_j2k_decode_tile(opj_j2k_t opj_event_msg(p_manager, EVT_ERROR, "Failed to decode.\n"); return OPJ_FALSE; } + p_j2k->m_tcd->enumcs = p_j2k->enumcs; - if (! opj_tcd_update_tile_data(p_j2k->m_tcd, p_data, p_data_size)) { - return OPJ_FALSE; - } + /* p_data can be set to NULL when the call will take care of using */ + /* itself the TCD data. This is typically the case for whole single */ + /* tile decoding optimization. */ + if (p_data != NULL) { + if (! opj_tcd_update_tile_data(p_j2k->m_tcd, p_data, p_data_size)) { + return OPJ_FALSE; + } - /* To avoid to destroy the tcp which can be useful when we try to decode a tile decoded before (cf j2k_random_tile_access) - * we destroy just the data which will be re-read in read_tile_header*/ - /*opj_j2k_tcp_destroy(l_tcp); - p_j2k->m_tcd->tcp = 0;*/ - opj_j2k_tcp_data_destroy(l_tcp); + /* To avoid to destroy the tcp which can be useful when we try to decode a tile decoded before (cf j2k_random_tile_access) + * we destroy just the data which will be re-read in read_tile_header*/ + /*opj_j2k_tcp_destroy(l_tcp); + p_j2k->m_tcd->tcp = 0;*/ + opj_j2k_tcp_data_destroy(l_tcp); + } p_j2k->m_specific_param.m_decoder.m_can_decode = 0; p_j2k->m_specific_param.m_decoder.m_state &= (~(OPJ_UINT32)J2K_STATE_DATA);