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