opj_j2k_write_sod(): avoid potential heap buffer overflow (fixes #1299) (probably master only)

This commit is contained in:
Even Rouault 2020-12-02 14:10:16 +01:00
parent 18b1138fbe
commit 73fdf28342
No known key found for this signature in database
GPG Key ID: 33EBBFC47B3DD87D
1 changed files with 7 additions and 2 deletions

View File

@ -4806,8 +4806,13 @@ static OPJ_BOOL opj_j2k_write_sod(opj_j2k_t *p_j2k,
}
}
assert(l_remaining_data >
p_j2k->m_specific_param.m_encoder.m_reserved_bytes_for_PLT);
if (l_remaining_data <
p_j2k->m_specific_param.m_encoder.m_reserved_bytes_for_PLT) {
opj_event_msg(p_manager, EVT_ERROR,
"Not enough bytes in output buffer to write SOD marker\n");
opj_tcd_marker_info_destroy(marker_info);
return OPJ_FALSE;
}
l_remaining_data -= p_j2k->m_specific_param.m_encoder.m_reserved_bytes_for_PLT;
if (! opj_tcd_encode_tile(p_tile_coder, p_j2k->m_current_tile_number,