Skip to content

Commit 1bba837

Browse files
authored
Merge pull request #1511 from rouault/fix_1488_bis
opj_t2_read_packet_header(): avoid unsigned integer overflow
2 parents 0f3ca81 + 017f2be commit 1bba837

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/lib/openjp2/t2.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,9 +1229,17 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2,
12291229
while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, (OPJ_INT32)i)) {
12301230
++i;
12311231
}
1232-
12331232
l_cblk->Mb = (OPJ_UINT32)l_band->numbps;
1234-
l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i;
1233+
if ((OPJ_UINT32)l_band->numbps + 1 < i) {
1234+
/* Not totally sure what we should do in that situation,
1235+
* but that avoids the integer overflow of
1236+
* https://github.com/uclouvain/openjpeg/pull/1488
1237+
* while keeping the regression test suite happy.
1238+
*/
1239+
l_cblk->numbps = (OPJ_UINT32)(l_band->numbps + 1 - (int)i);
1240+
} else {
1241+
l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i;
1242+
}
12351243
l_cblk->numlenbits = 3;
12361244
}
12371245

0 commit comments

Comments
 (0)