Blame SOURCES/jasper-CVE-2016-9391.patch

425a81
Backport of relevant parts of upstream commit:
425a81
425a81
From 1e84674d95353c64e5c4c0e7232ae86fd6ea813b Mon Sep 17 00:00:00 2001
425a81
From: Michael Adams <mdadams@ece.uvic.ca>
425a81
Date: Tue, 25 Oct 2016 07:01:50 -0700
425a81
Subject: [PATCH] Changed the JPC bitstream code to more gracefully handle a
425a81
 request for a larger sized integer than what can be handled (i.e., return
425a81
 with an error instead of failing an assert).
425a81
425a81
diff -pruN jasper-1.900.1.orig/src/libjasper/jpc/jpc_bs.c jasper-1.900.1/src/libjasper/jpc/jpc_bs.c
425a81
--- jasper-1.900.1.orig/src/libjasper/jpc/jpc_bs.c	2007-01-19 22:43:07.000000000 +0100
425a81
+++ jasper-1.900.1/src/libjasper/jpc/jpc_bs.c	2017-03-31 23:00:31.000000000 +0200
425a81
@@ -195,7 +195,10 @@ long jpc_bitstream_getbits(jpc_bitstream
425a81
 
425a81
 	/* We can reliably get at most 31 bits since ISO/IEC 9899 only
425a81
 	  guarantees that a long can represent values up to 2^31-1. */
425a81
-	assert(n >= 0 && n < 32);
425a81
+	//assert(n >= 0 && n < 32);
425a81
+	if (n < 0 || n >= 32) {
425a81
+		return -1;
425a81
+	}
425a81
 
425a81
 	/* Get the number of bits requested from the specified bit stream. */
425a81
 	v = 0;
425a81
@@ -215,7 +218,10 @@ int jpc_bitstream_putbits(jpc_bitstream_
425a81
 
425a81
 	/* We can reliably put at most 31 bits since ISO/IEC 9899 only
425a81
 	  guarantees that a long can represent values up to 2^31-1. */
425a81
-	assert(n >= 0 && n < 32);
425a81
+	//assert(n >= 0 && n < 32);
425a81
+	if (n < 0 || n >= 32) {
425a81
+		return EOF;
425a81
+	}
425a81
 	/* Ensure that only the bits to be output are nonzero. */
425a81
 	assert(!(v & (~JAS_ONES(n))));
425a81