Skip to content

Commit

Permalink
opj_t1_encode_cblk(): avoid undefined behaviour on fuzzed input (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jun 29, 2022
1 parent ca74961 commit dd1a2d6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/openjp2/t1.c
Original file line number Diff line number Diff line change
Expand Up @@ -2443,6 +2443,13 @@ static OPJ_FLOAT64 opj_t1_encode_cblk(opj_t1_t *t1,
OPJ_INT32 tmp = *datap;
if (tmp < 0) {
OPJ_UINT32 tmp_unsigned;
if (tmp == INT_MIN) {
/* To avoid undefined behaviour when negating INT_MIN */
/* but if we go here, it means we have supplied an input */
/* with more bit depth than we we can really support. */
/* Cf https://github.com/uclouvain/openjpeg/issues/1432 */
tmp = INT_MIN + 1;
}
max = opj_int_max(max, -tmp);
tmp_unsigned = opj_to_smr(tmp);
memcpy(datap, &tmp_unsigned, sizeof(OPJ_INT32));
Expand Down

0 comments on commit dd1a2d6

Please sign in to comment.