add comment on potential UB in j2k.c opj_j2k_setup_encoder

This commit is contained in:
Paul Dreik 2022-08-25 08:52:40 +02:00
parent 70050037b4
commit 01719f0423
1 changed files with 5 additions and 0 deletions

View File

@ -7817,6 +7817,11 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k,
image->comps[0].h * image->comps[0].prec) /
((double)parameters->tcp_rates[parameters->tcp_numlayers - 1] * 8 *
image->comps[0].dx * image->comps[0].dy));
// this is problematic because INT_MAX is converted to float, but
// it can not represent that value (2147483647) exactly, instead it
// becomes 2147483648.0f which means the else clause may be hit with
// the value 2147483648.0f. that can not be represented as an int,
// so the assignment to int is undefined behaviour
if (temp_size > INT_MAX) {
parameters->max_cs_size = INT_MAX;
} else {