File openjpeg2-CVE-2017-14151.patch of Package openjpeg2

diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c
index 2e116b2..2f50bfe 100644
--- a/src/lib/openjp2/tcd.c
+++ b/src/lib/openjp2/tcd.c
@@ -1087,10 +1087,13 @@ static OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_blo
 static OPJ_BOOL opj_tcd_code_block_enc_allocate_data (opj_tcd_cblk_enc_t * p_code_block)
 {
 	OPJ_UINT32 l_data_size;
-	
-	/* The +1 is needed for https://github.com/uclouvain/openjpeg/issues/835 */
-	l_data_size = 1 + (OPJ_UINT32)((p_code_block->x1 - p_code_block->x0) *
-	                               (p_code_block->y1 - p_code_block->y0) * (OPJ_INT32)sizeof(OPJ_UINT32));
+
+	/* +1 is needed for https://github.com/uclouvain/openjpeg/issues/835 */
+	/* and actually +2 required for https://github.com/uclouvain/openjpeg/issues/982 */
+	/* TODO: is there a theoretical upper-bound for the compressed code */
+	/* block size ? */
+	l_data_size = 2 + (OPJ_UINT32)((p_code_block->x1 - p_code_block->x0) *
+				       (p_code_block->y1 - p_code_block->y0) * (OPJ_INT32)sizeof(OPJ_UINT32));
 
 	if (l_data_size > p_code_block->data_size) {
 		if (p_code_block->data) {