File jasper-CVE-2018-20622.patch of Package jasper.18193

Index: jasper-2.0.14/src/libjasper/jpc/jpc_t2dec.c
===================================================================
--- jasper-2.0.14.orig/src/libjasper/jpc/jpc_t2dec.c
+++ jasper-2.0.14/src/libjasper/jpc/jpc_t2dec.c
@@ -225,6 +225,7 @@ hdroffstart = jas_stream_getrwcount(pkth
 	}
 
 	if ((present = jpc_bitstream_getbit(inb)) < 0) {
+		jpc_bitstream_close(inb);
 		return 1;
 	}
 	JAS_DBGLOG(10, ("\n", present));
@@ -252,10 +253,12 @@ hdroffstart = jas_stream_getrwcount(pkth
 				if (!cblk->numpasses) {
 					leaf = jpc_tagtree_getleaf(prc->incltagtree, usedcblkcnt - 1);
 					if ((included = jpc_tagtree_decode(prc->incltagtree, leaf, lyrno + 1, inb)) < 0) {
+						jpc_bitstream_close(inb);
 						return -1;
 					}
 				} else {
 					if ((included = jpc_bitstream_getbit(inb)) < 0) {
+						jpc_bitstream_close(inb);
 						return -1;
 					}
 				}
@@ -269,6 +272,7 @@ hdroffstart = jas_stream_getrwcount(pkth
 					leaf = jpc_tagtree_getleaf(prc->numimsbstagtree, usedcblkcnt - 1);
 					for (;;) {
 						if ((ret = jpc_tagtree_decode(prc->numimsbstagtree, leaf, i, inb)) < 0) {
+							jpc_bitstream_close(inb);
 							return -1;
 						}
 						if (ret) {
@@ -280,6 +284,7 @@ hdroffstart = jas_stream_getrwcount(pkth
 					cblk->firstpassno = cblk->numimsbs * 3;
 				}
 				if ((numnewpasses = jpc_getnumnewpasses(inb)) < 0) {
+					jpc_bitstream_close(inb);
 					return -1;
 				}
 				JAS_DBGLOG(10, ("numnewpasses=%d ", numnewpasses));
@@ -288,6 +293,7 @@ hdroffstart = jas_stream_getrwcount(pkth
 				mycounter = 0;
 				if (numnewpasses > 0) {
 					if ((m = jpc_getcommacode(inb)) < 0) {
+						jpc_bitstream_close(inb);
 						return -1;
 					}
 					cblk->numlenbits += m;
@@ -301,6 +307,7 @@ hdroffstart = jas_stream_getrwcount(pkth
 							maxpasses = -maxpasses;
 						if (!discard && !seg) {
 							if (!(seg = jpc_seg_alloc())) {
+								jpc_bitstream_close(inb);
 								return -1;
 							}
 							jpc_seglist_insert(&cblk->segs, cblk->segs.tail, seg);
@@ -315,6 +322,7 @@ hdroffstart = jas_stream_getrwcount(pkth
 						mycounter += n;
 						numnewpasses -= n;
 						if ((len = jpc_bitstream_getbits(inb, cblk->numlenbits + jpc_floorlog2(n))) < 0) {
+							jpc_bitstream_close(inb);
 							return -1;
 						}
 						JAS_DBGLOG(10, ("len=%d ", len));
@@ -336,6 +344,7 @@ hdroffstart = jas_stream_getrwcount(pkth
 	} else {
 		if (jpc_bitstream_inalign(inb, 0x7f, 0)) {
 			jas_eprintf("alignment failed\n");
+			jpc_bitstream_close(inb);
 			return -1;
 		}
 	}
openSUSE Build Service is sponsored by