Skip to content

Commit afb308b

Browse files
committed
Encoder: grow buffer size in opj_tcd_code_block_enc_allocate_data() to avoid write heap buffer overflow in opj_mqc_flush (#982)
1 parent 0b4c3ce commit afb308b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Diff for: src/lib/openjp2/tcd.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -1187,8 +1187,11 @@ static OPJ_BOOL opj_tcd_code_block_enc_allocate_data(opj_tcd_cblk_enc_t *
11871187
{
11881188
OPJ_UINT32 l_data_size;
11891189

1190-
/* The +1 is needed for https://github.com/uclouvain/openjpeg/issues/835 */
1191-
l_data_size = 1 + (OPJ_UINT32)((p_code_block->x1 - p_code_block->x0) *
1190+
/* +1 is needed for https://github.com/uclouvain/openjpeg/issues/835 */
1191+
/* and actually +2 required for https://github.com/uclouvain/openjpeg/issues/982 */
1192+
/* TODO: is there a theoretical upper-bound for the compressed code */
1193+
/* block size ? */
1194+
l_data_size = 2 + (OPJ_UINT32)((p_code_block->x1 - p_code_block->x0) *
11921195
(p_code_block->y1 - p_code_block->y0) * (OPJ_INT32)sizeof(OPJ_UINT32));
11931196

11941197
if (l_data_size > p_code_block->data_size) {

Diff for: tests/nonregression/test_suite.ctest.in

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ opj_compress -i @INPUT_NR_PATH@/Bretagne2.ppm -o @TEMP_PATH@/Bretagne2_empty_ban
169169
# Same rate as Bretagne2_4.j2k
170170
opj_compress -i @INPUT_NR_PATH@/Bretagne2.ppm -o @TEMP_PATH@/Bretagne2_empty_band_r800.j2k -t 2591,1943 -n 2 -r 800
171171

172+
opj_compress -i @INPUT_NR_PATH@/issue982.bmp -o @TEMP_PATH@/issue982.j2k -n 1
173+
172174
# DECODER TEST SUITE
173175
opj_decompress -i @INPUT_NR_PATH@/Bretagne2.j2k -o @TEMP_PATH@/Bretagne2.j2k.pgx
174176
opj_decompress -i @INPUT_NR_PATH@/_00042.j2k -o @TEMP_PATH@/_00042.j2k.pgx

0 commit comments

Comments
 (0)