File jasper-CVE-2021-3272.patch of Package jasper.18193

Index: jasper-2.0.14/src/libjasper/jp2/jp2_dec.c
===================================================================
--- jasper-2.0.14.orig/src/libjasper/jp2/jp2_dec.c
+++ jasper-2.0.14/src/libjasper/jp2/jp2_dec.c
@@ -253,7 +253,7 @@ jas_image_t *jp2_decode(jas_stream_t *in
 	  with the data in the code stream? */
 	if ((samedtype && dec->ihdr->data.ihdr.bpc != JP2_DTYPETOBPC(dtype)) ||
 	  (!samedtype && dec->ihdr->data.ihdr.bpc != JP2_IHDR_BPCNULL)) {
-		jas_eprintf("warning: component data type mismatch\n");
+		jas_eprintf("warning: component data type mismatch (IHDR)\n");
 	}
 
 	/* Is the compression type supported? */
@@ -276,7 +276,7 @@ jas_image_t *jp2_decode(jas_stream_t *in
 			  ++i) {
 				if (jas_image_cmptdtype(dec->image, i) !=
 				  JP2_BPCTODTYPE(dec->bpcc->data.bpcc.bpcs[i])) {
-					jas_eprintf("warning: component data type mismatch\n");
+					jas_eprintf("warning: component data type mismatch (BPCC)\n");
 				}
 			}
 		} else {
@@ -395,6 +395,14 @@ jas_image_t *jp2_decode(jas_stream_t *in
 		}
 	}
 
+	/* Ensure that the number of channels being used by the decoder
+	 * matches the number of image components. */
+	if (dec->numchans != jas_image_numcmpts(dec->image)) {
+		jas_eprintf("error: mismatch in number of components (%d != %d)\n",
+				dec->numchans, jas_image_numcmpts(dec->image));
+		goto error;
+	}
+
 	/* Mark all components as being of unknown type. */
 
 	for (i = 0; i < JAS_CAST(jas_uint, jas_image_numcmpts(dec->image)); ++i) {
openSUSE Build Service is sponsored by