[trunk] add a check on mandatory headers in Main Header (fixes issue 408)

This commit is contained in:
Antonin Descampe 2014-10-22 10:30:35 +00:00
parent aff9cb39ed
commit ad4fad0965
2 changed files with 30 additions and 0 deletions

View File

@ -7090,6 +7090,9 @@ OPJ_BOOL opj_j2k_read_header_procedure( opj_j2k_t *p_j2k,
OPJ_UINT32 l_current_marker; OPJ_UINT32 l_current_marker;
OPJ_UINT32 l_marker_size; OPJ_UINT32 l_marker_size;
const opj_dec_memory_marker_handler_t * l_marker_handler = 00; const opj_dec_memory_marker_handler_t * l_marker_handler = 00;
OPJ_BOOL l_has_siz = 0;
OPJ_BOOL l_has_cod = 0;
OPJ_BOOL l_has_qcd = 0;
/* preconditions */ /* preconditions */
assert(p_stream != 00); assert(p_stream != 00);
@ -7139,6 +7142,19 @@ OPJ_BOOL opj_j2k_read_header_procedure( opj_j2k_t *p_j2k,
l_marker_handler = opj_j2k_get_marker_handler(l_current_marker); l_marker_handler = opj_j2k_get_marker_handler(l_current_marker);
} }
if (l_marker_handler->id == J2K_MS_SIZ) {
/* Mark required SIZ marker as found */
l_has_siz = 1;
}
if (l_marker_handler->id == J2K_MS_COD) {
/* Mark required COD marker as found */
l_has_cod = 1;
}
if (l_marker_handler->id == J2K_MS_QCD) {
/* Mark required QCD marker as found */
l_has_qcd = 1;
}
/* Check if the marker is known and if it is the right place to find it */ /* Check if the marker is known and if it is the right place to find it */
if (! (p_j2k->m_specific_param.m_decoder.m_state & l_marker_handler->states) ) { if (! (p_j2k->m_specific_param.m_decoder.m_state & l_marker_handler->states) ) {
opj_event_msg(p_manager, EVT_ERROR, "Marker is not compliant with its position\n"); opj_event_msg(p_manager, EVT_ERROR, "Marker is not compliant with its position\n");
@ -7201,6 +7217,19 @@ OPJ_BOOL opj_j2k_read_header_procedure( opj_j2k_t *p_j2k,
opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_current_marker,2); opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_current_marker,2);
} }
if (l_has_siz == 0) {
opj_event_msg(p_manager, EVT_ERROR, "required SIZ marker not found in main header\n");
return OPJ_FALSE;
}
if (l_has_cod == 0) {
opj_event_msg(p_manager, EVT_ERROR, "required COD marker not found in main header\n");
return OPJ_FALSE;
}
if (l_has_qcd == 0) {
opj_event_msg(p_manager, EVT_ERROR, "required QCD marker not found in main header\n");
return OPJ_FALSE;
}
opj_event_msg(p_manager, EVT_INFO, "Main header has been correctly decoded.\n"); opj_event_msg(p_manager, EVT_INFO, "Main header has been correctly decoded.\n");
/* Position of the last element if the main header */ /* Position of the last element if the main header */

View File

@ -57,6 +57,7 @@ set(BLACKLIST_JPEG2000
gdal_fuzzer_unchecked_numresolutions.jp2 gdal_fuzzer_unchecked_numresolutions.jp2
mem-b2ace68c-1381.jp2 mem-b2ace68c-1381.jp2
1851.pdf.SIGSEGV.ce9.948.jp2 1851.pdf.SIGSEGV.ce9.948.jp2
1888.pdf.asan.35.988.jp2
) )
file(GLOB_RECURSE OPJ_DATA_NR_LIST file(GLOB_RECURSE OPJ_DATA_NR_LIST