Skip to content

Commit

Permalink
Fix potential use-after-free in opj_j2k_write_mco function
Browse files Browse the repository at this point in the history
Fixes #563
  • Loading branch information
mayeut committed Sep 6, 2015
1 parent c31fb68 commit 940100c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib/openjp2/j2k.c
Original file line number Diff line number Diff line change
Expand Up @@ -5559,8 +5559,7 @@ static OPJ_BOOL opj_j2k_write_mco( opj_j2k_t *p_j2k,
assert(p_stream != 00);

l_tcp =&(p_j2k->m_cp.tcps[p_j2k->m_current_tile_number]);
l_current_data = p_j2k->m_specific_param.m_encoder.m_header_tile_data;


l_mco_size = 5 + l_tcp->m_nb_mcc_records;
if (l_mco_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {

Expand All @@ -5575,6 +5574,8 @@ static OPJ_BOOL opj_j2k_write_mco( opj_j2k_t *p_j2k,
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_mco_size;
}
l_current_data = p_j2k->m_specific_param.m_encoder.m_header_tile_data;


opj_write_bytes(l_current_data,J2K_MS_MCO,2); /* MCO */
l_current_data += 2;
Expand All @@ -5586,10 +5587,9 @@ static OPJ_BOOL opj_j2k_write_mco( opj_j2k_t *p_j2k,
++l_current_data;

l_mcc_record = l_tcp->m_mcc_records;
for (i=0;i<l_tcp->m_nb_mcc_records;++i) {
for (i=0;i<l_tcp->m_nb_mcc_records;++i) {
opj_write_bytes(l_current_data,l_mcc_record->m_index,1);/* Imco -> use the mcc indicated by 1*/
++l_current_data;

++l_mcc_record;
}

Expand Down

0 comments on commit 940100c

Please sign in to comment.