Skip to content

Commit

Permalink
opj_t2_read_packet_header(): avoid unsigned integer overflow (alterna…
Browse files Browse the repository at this point in the history
…te fix to #1488)
  • Loading branch information
rouault committed Feb 18, 2024
1 parent 0f3ca81 commit 508b0be
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib/openjp2/t2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1229,9 +1229,18 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2,
while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, (OPJ_INT32)i)) {
++i;
}

l_cblk->Mb = (OPJ_UINT32)l_band->numbps;
l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i;
if((OPJ_UINT32)l_band->numbps + 1 < i) {
/* Not totally sure what we should do in that situation,
* but that avoids the integer overflow of
* https://github.com/uclouvain/openjpeg/pull/1488
* while keeping the regression test suite happy.
*/
l_cblk->numbps = (OPJ_UINT32)(l_band->numbps + 1 - (int)i);
}
else {
l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i;
}
l_cblk->numlenbits = 3;
}

Expand Down

0 comments on commit 508b0be

Please sign in to comment.