about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--LICENSES/JasPer-2.0.txt51
-rw-r--r--REUSE.toml7
-rw-r--r--loftix/bugs.scm13
-rw-r--r--patches/jasper-lint.patch592
-rw-r--r--patches/jasper-sanitized-bmp.patch117
5 files changed, 775 insertions, 5 deletions
diff --git a/LICENSES/JasPer-2.0.txt b/LICENSES/JasPer-2.0.txt
new file mode 100644
index 0000000..ce90e4b
--- /dev/null
+++ b/LICENSES/JasPer-2.0.txt
@@ -0,0 +1,51 @@
+JasPer License Version 2.0
+
+Copyright (c) 2001-2016 Michael David Adams
+Copyright (c) 1999-2000 Image Power, Inc.
+Copyright (c) 1999-2000 The University of British Columbia
+
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person (the
+"User") obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge,
+publish, distribute, and/or sell copies of the Software, and to permit
+persons to whom the Software is furnished to do so, subject to the
+following conditions:
+
+1.  The above copyright notices and this permission notice (which
+includes the disclaimer below) shall be included in all copies or
+substantial portions of the Software.
+
+2.  The name of a copyright holder shall not be used to endorse or
+promote products derived from the Software without specific prior
+written permission.
+
+THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
+LICENSE.  NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+THIS DISCLAIMER.  THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
+"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  IN NO
+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  NO ASSURANCES ARE
+PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
+THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
+EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
+BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
+PROPERTY RIGHTS OR OTHERWISE.  AS A CONDITION TO EXERCISING THE RIGHTS
+GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
+ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY.  THE SOFTWARE
+IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
+SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
+AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
+SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
+THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
+PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
+RISK ACTIVITIES").  THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
+EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
+
diff --git a/REUSE.toml b/REUSE.toml
index a89054f..f1ae1ec 100644
--- a/REUSE.toml
+++ b/REUSE.toml
@@ -186,11 +186,16 @@ SPDX-FileCopyrightText = 'Paul Eggert'
 SPDX-License-Identifier = 'GPL-3.0-or-later'
 
 [[annotations]]
+path = [ 'patches/jasper-lint.patch',
+         'patches/jasper-sanitized-bmp.patch' ]
+SPDX-FileCopyrightText = 'Michael Adams'
+SPDX-License-Identifier = 'JasPer-2.0'
+
+[[annotations]]
 path = 'patches/fuzzolic-showmap.patch'
 SPDX-FileCopyrightText = 'Emilio Coppa'
 SPDX-License-Identifier = 'GPL-2.0-or-later'
 
-
 [[annotations]]
 path = 'patches/fuzzolic-timeout-solver.patch'
 SPDX-FileCopyrightText = 'Andrew Haberlandt'
diff --git a/loftix/bugs.scm b/loftix/bugs.scm
index db5f911..7b63a28 100644
--- a/loftix/bugs.scm
+++ b/loftix/bugs.scm
@@ -240,12 +240,17 @@
   (with-ubsan jasper-1.900.19))
 
 (define-public jasper-1.900.5
-  (jasper-at-version "1.900.5"
-                     "1fvy4ngc6064g128q4484qpinsn05y9qw6lrccc4czhalla2w26m"))
+  (with-patches
+   (jasper-at-version "1.900.5"
+                      "1fvy4ngc6064g128q4484qpinsn05y9qw6lrccc4czhalla2w26m")
+   "patches/jasper-lint.patch"))
 
 (define-public jasper-1.900.3
-  (jasper-at-version "1.900.3"
-                     "106xwiyn40k5yrnny198mzscvyd18rza9clhd2nl6xvcsz73swrn"))
+  (with-patches
+   (jasper-at-version "1.900.3"
+                      "106xwiyn40k5yrnny198mzscvyd18rza9clhd2nl6xvcsz73swrn")
+   "patches/jasper-lint.patch"
+   "patches/jasper-sanitized-bmp.patch"))
 
 (define-public libarchive-3.2.0
   (package
diff --git a/patches/jasper-lint.patch b/patches/jasper-lint.patch
new file mode 100644
index 0000000..89bc2f9
--- /dev/null
+++ b/patches/jasper-lint.patch
@@ -0,0 +1,592 @@
+commit d743f7e0ad901dc3419fc1042939a5454de96c16
+Author: Michael Adams <mdadams@ece.uvic.ca>
+Date:   2016-10-21 03:14:31 -0700
+
+    Changed the configure setup so that if GCC is used warnings and pedantic
+    errors are enabled.
+    
+    Fixed some inconsistent use of quotes and angle brackets in include directives.
+    
+    Added experimental support in the jas_image code for images with signed
+    sample values.  This code has not been tested yet, except to ensure
+    it does not crash.
+    
+    Fixed a bug in the stream code (jas_stream) that caused memory to leak
+    when an attempt to open a file failed.
+    
+    Commented out an assertion that causes a C99 pedantic build to fail, due
+    to string literal that is too long.
+    
+    In the JPC QMFB/TSFB code, there were several places in function
+    declarations/definitions where incorrect parameter types were used
+    (e.g., int* used instead of jpc_fix_t*).
+    Also, some function prototypes were missing.
+    This is now fixed.
+    
+    Some files were missing includes for jas_debug.h (resulting in missing
+    function prototypes).  This is now fixed.
+    
+    Some bugs in the MIF decoder have been fixed.
+    Also, some improved debugging support has been added for the MIF decoder.
+    
+    Numerous cosmetic changes were also made to the code.
+
+diff --git a/configure.ac b/configure.ac
+index 13751b0e9bef..7f28f3ffb4e7 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -375,10 +375,11 @@ esac
+ ], [debug=no])
+ 
+ if test "$GCC" = yes; then
+-	CFLAGS="$CFLAGS"
+-	#CFLAGS="$CFLAGS -std=c99"
+-	#CFLAGS="$CFLAGS -pedantic"
+-	#CFLAGS="$CFLAGS -pedantic-errors"
++	#CFLAGS="$CFLAGS"
++	CFLAGS="$CFLAGS -std=c99"
++	CFLAGS="$CFLAGS -pedantic"
++	CFLAGS="$CFLAGS -pedantic-errors"
++	CFLAGS="$CFLAGS -Wall"
+ 	#CFLAGS="$CFLAGS -W -Wall -Wno-long-long -Wformat -Wmissing-prototypes -Wstrict-prototypes"
+ fi
+ 
+diff --git a/src/appl/jasper.c b/src/appl/jasper.c
+index d99e35668bd9..690002958c26 100644
+--- a/src/appl/jasper.c
++++ b/src/appl/jasper.c
+@@ -77,6 +77,7 @@
+ #include <time.h>
+ 
+ #include <jasper/jasper.h>
++#include <jasper/jas_debug.h>
+ 
+ /******************************************************************************\
+ *
+diff --git a/src/libjasper/base/jas_cm.c b/src/libjasper/base/jas_cm.c
+index 6c612b70f7a7..fc8417fb65ba 100644
+--- a/src/libjasper/base/jas_cm.c
++++ b/src/libjasper/base/jas_cm.c
+@@ -65,16 +65,17 @@
+  * $Id$
+  */
+ 
+-#include <jasper/jas_config.h>
+ #include <math.h>
+ #include <stdlib.h>
+ #include <assert.h>
+-#include <jasper/jas_cm.h>
+-#include <jasper/jas_icc.h>
+-#include <jasper/jas_init.h>
+-#include <jasper/jas_stream.h>
+-#include <jasper/jas_malloc.h>
+-#include <jasper/jas_math.h>
++#include "jasper/jas_config.h"
++#include "jasper/jas_cm.h"
++#include "jasper/jas_icc.h"
++#include "jasper/jas_init.h"
++#include "jasper/jas_stream.h"
++#include "jasper/jas_malloc.h"
++#include "jasper/jas_math.h"
++#include "jasper/jas_debug.h"
+ 
+ static jas_cmprof_t *jas_cmprof_create(void);
+ static void jas_cmshapmatlut_cleanup(jas_cmshapmatlut_t *);
+diff --git a/src/libjasper/base/jas_getopt.c b/src/libjasper/base/jas_getopt.c
+index 2a3dfe50addf..9c9724aebe6d 100644
+--- a/src/libjasper/base/jas_getopt.c
++++ b/src/libjasper/base/jas_getopt.c
+@@ -76,6 +76,7 @@
+ 
+ #include "jasper/jas_getopt.h"
+ #include "jasper/jas_math.h"
++#include "jasper/jas_debug.h"
+ 
+ /******************************************************************************\
+ * Global data.
+diff --git a/src/libjasper/base/jas_icc.c b/src/libjasper/base/jas_icc.c
+index 6569bd9dd524..4abee31b9602 100644
+--- a/src/libjasper/base/jas_icc.c
++++ b/src/libjasper/base/jas_icc.c
+@@ -60,14 +60,15 @@
+  */
+ 
+ #include <assert.h>
+-#include <jasper/jas_config.h>
+-#include <jasper/jas_types.h>
+-#include <jasper/jas_malloc.h>
+-#include <jasper/jas_debug.h>
+-#include <jasper/jas_icc.h>
+-#include <jasper/jas_cm.h>
+-#include <jasper/jas_stream.h>
+-#include <jasper/jas_string.h>
++
++#include "jasper/jas_config.h"
++#include "jasper/jas_types.h"
++#include "jasper/jas_malloc.h"
++#include "jasper/jas_debug.h"
++#include "jasper/jas_icc.h"
++#include "jasper/jas_cm.h"
++#include "jasper/jas_stream.h"
++#include "jasper/jas_string.h"
+ 
+ #include <stdlib.h>
+ #include <ctype.h>
+diff --git a/src/libjasper/base/jas_image.c b/src/libjasper/base/jas_image.c
+index 04adbba95a28..9d2669ad863f 100644
+--- a/src/libjasper/base/jas_image.c
++++ b/src/libjasper/base/jas_image.c
+@@ -81,6 +81,7 @@
+ #include "jasper/jas_image.h"
+ #include "jasper/jas_malloc.h"
+ #include "jasper/jas_string.h"
++#include "jasper/jas_debug.h"
+ 
+ /******************************************************************************\
+ * Types.
+@@ -1227,13 +1228,38 @@ static void jas_image_calcbbox2(jas_image_t *image, jas_image_coord_t *tlx,
+ 	*bry = tmpbry;
+ }
+ 
++static inline long decode_twos_comp(ulong c, int prec)
++{
++	long result;
++	assert(prec >= 2);
++	jas_eprintf("warning: support for signed data is untested\n");
++	// NOTE: Is this correct?
++	result = (c & ((1 << (prec - 1)) - 1)) - (c & (1 << (prec - 1)));
++	return result;
++}
+ 
++static inline ulong encode_twos_comp(long n, int prec)
++{
++	ulong result;
++	assert(prec >= 2);
++	jas_eprintf("warning: support for signed data is untested\n");
++	// NOTE: Is this correct?
++	if (n < 0) {
++		result = -n;
++		result = (result ^ 0xffffffffUL) + 1;
++		result &= (1 << prec) - 1;
++	} else {
++		result = n;
++	}
++	return result;
++}
+ 
+ static int getint(jas_stream_t *in, int sgnd, int prec, long *val)
+ {
+ 	long v;
+ 	int n;
+ 	int c;
++	assert((!sgnd && prec >= 1) || (sgnd && prec >= 2));
+ 	n = (prec + 7) / 8;
+ 	v = 0;
+ 	while (--n >= 0) {
+@@ -1243,8 +1269,7 @@ static int getint(jas_stream_t *in, int sgnd, int prec, long *val)
+ 	}
+ 	v &= ((1 << prec) - 1);
+ 	if (sgnd) {
+-		/* XXX - Do something here. */
+-		abort();
++		*val = decode_twos_comp(v, prec);
+ 	} else {
+ 		*val = v;
+ 	}
+@@ -1255,10 +1280,13 @@ static int putint(jas_stream_t *out, int sgnd, int prec, long val)
+ {
+ 	int n;
+ 	int c;
++	bool s;
++	ulong tmp;
++	assert((!sgnd && prec >= 1) || (sgnd && prec >= 2));
+ 	if (sgnd) {
+-		/* XXX - Do something here. */
+-		abort();
++		val = encode_twos_comp(val, prec);
+ 	}
++	assert(val >= 0);
+ 	val &= (1 << prec) - 1;
+ 	n = (prec + 7) / 8;
+ 	while (--n >= 0) {
+@@ -1342,16 +1370,20 @@ jas_image_dump(image, stderr);
+ 		for (i = 1; i < jas_image_numcmpts(inimage); ++i) {
+ 			hstep = jas_image_cmpthstep(inimage, i);
+ 			vstep = jas_image_cmptvstep(inimage, i);
+-			if (hstep < minhstep)
++			if (hstep < minhstep) {
+ 				minhstep = hstep;
+-			if (vstep < minvstep)
++			}
++			if (vstep < minvstep) {
+ 				minvstep = vstep;
++			}
+ 		}
+ 		n = jas_image_numcmpts(inimage);
+ 		for (i = 0; i < n; ++i) {
+ 			cmpttype = jas_image_cmpttype(inimage, i);
+-			if (jas_image_sampcmpt(inimage, i, i + 1, 0, 0, minhstep, minvstep, jas_image_cmptsgnd(inimage, i), jas_image_cmptprec(inimage, i)))
++			if (jas_image_sampcmpt(inimage, i, i + 1, 0, 0, minhstep, minvstep,
++			  jas_image_cmptsgnd(inimage, i), jas_image_cmptprec(inimage, i))) {
+ 				goto error;
++			}
+ 			jas_image_setcmpttype(inimage, i + 1, cmpttype);
+ 			jas_image_delcmpt(inimage, i);
+ 		}
+@@ -1362,8 +1394,9 @@ jas_image_dump(image, stderr);
+ 	hstep = jas_image_cmpthstep(inimage, 0);
+ 	vstep = jas_image_cmptvstep(inimage, 0);
+ 
+-	inprof = jas_image_cmprof(inimage);
+-	assert(inprof);
++	if (!(inprof = jas_image_cmprof(inimage))) {
++		abort();
++	}
+ 	numinclrchans = jas_clrspc_numchans(jas_cmprof_clrspc(inprof));
+ 	numinauxchans = jas_image_numcmpts(inimage) - numinclrchans;
+ 	numoutclrchans = jas_clrspc_numchans(jas_cmprof_clrspc(outprof));
+@@ -1371,8 +1404,9 @@ jas_image_dump(image, stderr);
+ 	numoutchans = numoutclrchans + numoutauxchans;
+ 	prec = 8;
+ 
+-	if (!(outimage = jas_image_create0()))
++	if (!(outimage = jas_image_create0())) {
+ 		goto error;
++	}
+ 
+ 	/* Create a component for each of the colorants. */
+ 	for (i = 0; i < numoutclrchans; ++i) {
+@@ -1456,11 +1490,13 @@ jas_image_dump(image, stderr);
+ 		}
+ 	}
+ 
+-	for (i = 0; i < numoutclrchans; ++i)
++	for (i = 0; i < numoutclrchans; ++i) {
+ 		jas_free(outcmptfmts[i].buf);
++	}
+ 	jas_free(outcmptfmts);
+-	for (i = 0; i < numinclrchans; ++i)
++	for (i = 0; i < numinclrchans; ++i) {
+ 		jas_free(incmptfmts[i].buf);
++	}
+ 	jas_free(incmptfmts);
+ 	jas_cmxform_destroy(xform);
+ 	jas_image_destroy(inimage);
+diff --git a/src/libjasper/base/jas_stream.c b/src/libjasper/base/jas_stream.c
+index 29e4291cb689..ac51ce25a38a 100644
+--- a/src/libjasper/base/jas_stream.c
++++ b/src/libjasper/base/jas_stream.c
+@@ -283,6 +283,9 @@ jas_stream_t *jas_stream_fopen(const char *filename, const char *mode)
+ 
+ 	/* Open the underlying file. */
+ 	if ((obj->fd = open(filename, openflags, JAS_STREAM_PERMS)) < 0) {
++		// Free the underlying file object, since it will not otherwise
++		// be freed.
++		jas_free(obj);
+ 		jas_stream_destroy(stream);
+ 		return 0;
+ 	}
+diff --git a/src/libjasper/include/jasper/jas_debug.h b/src/libjasper/include/jasper/jas_debug.h
+index 2223c6caae15..1619a5ac7684 100644
+--- a/src/libjasper/include/jasper/jas_debug.h
++++ b/src/libjasper/include/jasper/jas_debug.h
+@@ -75,8 +75,8 @@
+ #include <stdio.h>
+ 
+ #include <jasper/jas_config.h>
+-#include "jasper/jas_types.h"
+-#include "jasper/jas_debug.h"
++#include <jasper/jas_types.h>
++#include <jasper/jas_debug.h>
+ 
+ #ifdef __cplusplus
+ extern "C" {
+diff --git a/src/libjasper/include/jasper/jas_fix.h b/src/libjasper/include/jasper/jas_fix.h
+index f91ce25f2100..e9164c7ac4ca 100644
+--- a/src/libjasper/include/jasper/jas_fix.h
++++ b/src/libjasper/include/jasper/jas_fix.h
+@@ -80,6 +80,7 @@
+ 
+ #include <jasper/jas_config.h>
+ #include <jasper/jas_types.h>
++#include <jasper/jas_debug.h>
+ 
+ #ifdef __cplusplus
+ extern "C" {
+diff --git a/src/libjasper/jpc/jpc_bs.c b/src/libjasper/jpc/jpc_bs.c
+index c3dd466f8815..f87a40c4b07e 100644
+--- a/src/libjasper/jpc/jpc_bs.c
++++ b/src/libjasper/jpc/jpc_bs.c
+@@ -97,8 +97,7 @@ jpc_bitstream_t *jpc_bitstream_sopen(jas_stream_t *stream, char *mode)
+ 	jpc_bitstream_t *bitstream;
+ 
+ 	/* Ensure that the open mode is valid. */
+-#if 1
+-/* This causes a string literal too long error (with c99 pedantic mode). */
++#if 0 /* This causes a string literal too long error (with c99 pedantic mode).  Why is this so? */
+ 	assert(!strcmp(mode, "r") || !strcmp(mode, "w") || !strcmp(mode, "r+")
+ 	  || !strcmp(mode, "w+"));
+ #endif
+diff --git a/src/libjasper/jpc/jpc_qmfb.c b/src/libjasper/jpc/jpc_qmfb.c
+index af874b4c01b5..bc57b668b57c 100644
+--- a/src/libjasper/jpc/jpc_qmfb.c
++++ b/src/libjasper/jpc/jpc_qmfb.c
+@@ -96,7 +96,7 @@
+ 
+ int jpc_ft_analyze(jpc_fix_t *a, int xstart, int ystart, int width, int height,
+   int stride);
+-int jpc_ft_synthesize(int *a, int xstart, int ystart, int width, int height,
++int jpc_ft_synthesize(jpc_fix_t *a, int xstart, int ystart, int width, int height,
+   int stride);
+ 
+ int jpc_ns_analyze(jpc_fix_t *a, int xstart, int ystart, int width, int height,
+@@ -1528,7 +1528,7 @@ int jpc_ft_analyze(jpc_fix_t *a, int xstart, int ystart, int width, int height,
+ 
+ }
+ 
+-int jpc_ft_synthesize(int *a, int xstart, int ystart, int width, int height,
++int jpc_ft_synthesize(jpc_fix_t *a, int xstart, int ystart, int width, int height,
+   int stride)
+ {
+ 	int numrows = height;
+diff --git a/src/libjasper/jpc/jpc_qmfb.h b/src/libjasper/jpc/jpc_qmfb.h
+index 75611fe940e4..7bef848eb9bc 100644
+--- a/src/libjasper/jpc/jpc_qmfb.h
++++ b/src/libjasper/jpc/jpc_qmfb.h
+@@ -75,6 +75,7 @@
+ \******************************************************************************/
+ 
+ #include "jasper/jas_seq.h"
++#include "jpc_fix.h"
+ 
+ /******************************************************************************\
+ * Constants.
+@@ -101,8 +102,8 @@ any particular platform.  Hopefully, it is not too unreasonable, however. */
+ #endif
+ 
+ typedef struct {
+-	int (*analyze)(int *, int, int, int, int, int);
+-	int (*synthesize)(int *, int, int, int, int, int);
++	int (*analyze)(jpc_fix_t *, int, int, int, int, int);
++	int (*synthesize)(jpc_fix_t *, int, int, int, int, int);
+ 	double *lpenergywts;
+ 	double *hpenergywts;
+ } jpc_qmfb2d_t;
+diff --git a/src/libjasper/jpc/jpc_t1dec.c b/src/libjasper/jpc/jpc_t1dec.c
+index 8bbe83a5b269..b491ec3b9752 100644
+--- a/src/libjasper/jpc/jpc_t1dec.c
++++ b/src/libjasper/jpc/jpc_t1dec.c
+@@ -78,6 +78,7 @@
+ #include "jasper/jas_fix.h"
+ #include "jasper/jas_stream.h"
+ #include "jasper/jas_math.h"
++#include "jasper/jas_debug.h"
+ 
+ #include "jpc_bs.h"
+ #include "jpc_mqdec.h"
+diff --git a/src/libjasper/jpc/jpc_tsfb.c b/src/libjasper/jpc/jpc_tsfb.c
+index b51b747d6931..50f1437da0cb 100644
+--- a/src/libjasper/jpc/jpc_tsfb.c
++++ b/src/libjasper/jpc/jpc_tsfb.c
+@@ -81,6 +81,7 @@
+ #include "jpc_cs.h"
+ #include "jpc_util.h"
+ #include "jpc_math.h"
++#include "jpc_fix.h"
+ 
+ void jpc_tsfb_getbands2(jpc_tsfb_t *tsfb, int locxstart, int locystart,
+   int xstart, int ystart, int xend, int yend, jpc_tsfb_band_t **bands,
+@@ -127,7 +128,7 @@ int jpc_tsfb_analyze(jpc_tsfb_t *tsfb, jas_seq2d_t *a)
+ 	  jas_seq2d_height(a), jas_seq2d_rowstep(a), tsfb->numlvls - 1) : 0;
+ }
+ 
+-int jpc_tsfb_analyze2(jpc_tsfb_t *tsfb, int *a, int xstart, int ystart,
++int jpc_tsfb_analyze2(jpc_tsfb_t *tsfb, jpc_fix_t *a, int xstart, int ystart,
+   int width, int height, int stride, int numlvls)
+ {
+ 	if (width > 0 && height > 0) {
+@@ -155,7 +156,7 @@ int jpc_tsfb_synthesize(jpc_tsfb_t *tsfb, jas_seq2d_t *a)
+ 	  jas_seq2d_height(a), jas_seq2d_rowstep(a), tsfb->numlvls - 1) : 0;
+ }
+ 
+-int jpc_tsfb_synthesize2(jpc_tsfb_t *tsfb, int *a, int xstart, int ystart,
++int jpc_tsfb_synthesize2(jpc_tsfb_t *tsfb, jpc_fix_t *a, int xstart, int ystart,
+   int width, int height, int stride, int numlvls)
+ {
+ 	if (numlvls > 0) {
+diff --git a/src/libjasper/jpc/jpc_tsfb.h b/src/libjasper/jpc/jpc_tsfb.h
+index 1bf9736ae834..33f11f4430d1 100644
+--- a/src/libjasper/jpc/jpc_tsfb.h
++++ b/src/libjasper/jpc/jpc_tsfb.h
+@@ -130,6 +130,12 @@ int jpc_tsfb_analyze(jpc_tsfb_t *tsfb, jas_seq2d_t *x);
+ /* Perform synthesis. */
+ int jpc_tsfb_synthesize(jpc_tsfb_t *tsfb, jas_seq2d_t *x);
+ 
++int jpc_tsfb_analyze2(jpc_tsfb_t *tsfb, jpc_fix_t *a, int xstart, int ystart,
++  int width, int height, int stride, int numlvls);
++
++int jpc_tsfb_synthesize2(jpc_tsfb_t *tsfb, jpc_fix_t *a, int xstart, int ystart,
++  int width, int height, int stride, int numlvls);
++
+ /* Get band information for a TSFB. */
+ int jpc_tsfb_getbands(jpc_tsfb_t *tsfb, uint_fast32_t xstart,
+   uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend,
+diff --git a/src/libjasper/jpg/jpg_dummy.c b/src/libjasper/jpg/jpg_dummy.c
+index db70fca8d860..bc8b7c5182df 100644
+--- a/src/libjasper/jpg/jpg_dummy.c
++++ b/src/libjasper/jpg/jpg_dummy.c
+@@ -69,6 +69,7 @@
+ #include "jasper/jas_stream.h"
+ #include "jasper/jas_image.h"
+ #include "jasper/jas_string.h"
++#include "jasper/jas_debug.h"
+ 
+ #include "jpg_cod.h"
+ 
+diff --git a/src/libjasper/mif/mif_cod.c b/src/libjasper/mif/mif_cod.c
+index 5541a22f02d2..724df93c2f0f 100644
+--- a/src/libjasper/mif/mif_cod.c
++++ b/src/libjasper/mif/mif_cod.c
+@@ -70,6 +70,7 @@
+ #include "jasper/jas_image.h"
+ #include "jasper/jas_string.h"
+ #include "jasper/jas_malloc.h"
++#include "jasper/jas_debug.h"
+ 
+ #include "mif_cod.h"
+ 
+@@ -175,6 +176,7 @@ jas_image_t *mif_decode(jas_stream_t *in, char *optstr)
+ 		cmpt = hdr->cmpts[cmptno];
+ 		tmpstream = cmpt->data ? jas_stream_fopen(cmpt->data, "rb") : in;
+ 		if (!tmpstream) {
++			jas_eprintf("cannot open component file %s\n", cmpt->data);
+ 			goto error;
+ 		}
+ 		if (!(tmpimage = jas_image_decode(tmpstream, -1, 0))) {
+@@ -482,26 +484,38 @@ static mif_hdr_t *mif_hdr_get(jas_stream_t *in)
+ 	done = false;
+ 	do {
+ 		if (!mif_getline(in, buf, sizeof(buf))) {
++			jas_eprintf("mif_getline failed\n");
+ 			goto error;
+ 		}
+ 		if (buf[0] == '\0') {
+ 			continue;
+ 		}
++		JAS_DBGLOG(10, ("header line: len=%d; %s\n", strlen(buf), buf));
+ 		if (!(tvp = jas_tvparser_create(buf))) {
++			jas_eprintf("jas_tvparser_create failed\n");
+ 			goto error;
+ 		}
+ 		if (jas_tvparser_next(tvp)) {
++			jas_eprintf("jas_tvparser_next failed\n");
+ 			abort();
+ 		}
+-		id = jas_taginfo_nonull(jas_taginfos_lookup(mif_tags2, jas_tvparser_gettag(tvp)))->id;
++		id = jas_taginfo_nonull(jas_taginfos_lookup(mif_tags2,
++		  jas_tvparser_gettag(tvp)))->id;
+ 		jas_tvparser_destroy(tvp);
+ 		switch (id) {
+ 		case MIF_CMPT:
+-			mif_process_cmpt(hdr, buf);
++			if (mif_process_cmpt(hdr, buf)) {
++				jas_eprintf("cannot get component information\n");
++				goto error;
++			}
+ 			break;
+ 		case MIF_END:
+ 			done = 1;
+ 			break;
++		default:
++			jas_eprintf("invalid header information: %s\n", buf);
++			goto error;
++			break;
+ 		}
+ 	} while (!done);
+ 
+@@ -524,6 +538,7 @@ static int mif_process_cmpt(mif_hdr_t *hdr, char *buf)
+ 	tvp = 0;
+ 
+ 	if (!(cmpt = mif_cmpt_create())) {
++		jas_eprintf("cannot create component\n");
+ 		goto error;
+ 	}
+ 	cmpt->tlx = 0;
+@@ -537,8 +552,16 @@ static int mif_process_cmpt(mif_hdr_t *hdr, char *buf)
+ 	cmpt->data = 0;
+ 
+ 	if (!(tvp = jas_tvparser_create(buf))) {
++		jas_eprintf("cannot create parser\n");
+ 		goto error;
+ 	}
++
++	// Skip the component keyword
++	if ((id = jas_tvparser_next(tvp))) {
++		abort();
++	}
++
++	// Process the tag-value pairs.
+ 	while (!(id = jas_tvparser_next(tvp))) {
+ 		switch (jas_taginfo_nonull(jas_taginfos_lookup(mif_tags,
+ 		  jas_tvparser_gettag(tvp)))->id) {
+@@ -571,12 +594,20 @@ static int mif_process_cmpt(mif_hdr_t *hdr, char *buf)
+ 				goto error;
+ 			}
+ 			break;
++		default:
++			jas_eprintf("invalid component information: %s\n", buf);
++			goto error;
++			break;
+ 		}
+ 	}
+ 	if (!cmpt->sampperx || !cmpt->samppery) {
+ 		goto error;
+ 	}
++	if (!cmpt->width || !cmpt->height || !cmpt->prec || cmpt->sgnd < 0) {
++		goto error;
++	}
+ 	if (mif_hdr_addcmpt(hdr, hdr->numcmpts, cmpt)) {
++		jas_eprintf("cannot add component\n");
+ 		goto error;
+ 	}
+ 	jas_tvparser_destroy(tvp);
+@@ -695,15 +726,16 @@ static int mif_getc(jas_stream_t *in)
+ 	do {
+ 		switch (c = jas_stream_getc(in)) {
+ 		case EOF:
+-			done = 1;
++			done = true;
+ 			break;
+ 		case '#':
+ 			for (;;) {
+ 				if ((c = jas_stream_getc(in)) == EOF) {
+-					done = 1;
++					done = true;
+ 					break;
+ 				}	
+ 				if (c == '\n') {
++					done = true;
+ 					break;
+ 				}
+ 			}
+@@ -714,7 +746,7 @@ static int mif_getc(jas_stream_t *in)
+ 			}
+ 			break;
+ 		default:
+-			done = 1;
++			done = true;
+ 			break;
+ 		}
+ 	} while (!done);
+diff --git a/src/libjasper/pnm/pnm_dec.c b/src/libjasper/pnm/pnm_dec.c
+index f2ca26e0ac9b..9de7cb7424eb 100644
+--- a/src/libjasper/pnm/pnm_dec.c
++++ b/src/libjasper/pnm/pnm_dec.c
+@@ -79,6 +79,7 @@
+ #include "jasper/jas_types.h"
+ #include "jasper/jas_stream.h"
+ #include "jasper/jas_image.h"
++#include "jasper/jas_debug.h"
+ 
+ #include "pnm_cod.h"
+ 
diff --git a/patches/jasper-sanitized-bmp.patch b/patches/jasper-sanitized-bmp.patch
new file mode 100644
index 0000000..d02ee91
--- /dev/null
+++ b/patches/jasper-sanitized-bmp.patch
@@ -0,0 +1,117 @@
+commit 8f62b4761711d036fd8964df256b938c809b7fca
+Author: Michael Adams <mdadams@ece.uvic.ca>
+Date:   2016-10-15 20:32:23 -0700
+
+    Fixed a sanitizer failure in the BMP codec.
+    Also, added a --debug-level command line option to the imginfo command
+    for debugging purposes.
+
+diff --git a/src/appl/imginfo.c b/src/appl/imginfo.c
+index 8af19e98aed7..f458a9770e55 100644
+--- a/src/appl/imginfo.c
++++ b/src/appl/imginfo.c
+@@ -85,7 +85,8 @@ typedef enum {
+ 	OPT_HELP,
+ 	OPT_VERSION,
+ 	OPT_VERBOSE,
+-	OPT_INFILE
++	OPT_INFILE,
++	OPT_DEBUG
+ } optid_t;
+ 
+ /******************************************************************************\
+@@ -104,6 +105,7 @@ static jas_opt_t opts[] = {
+ 	{OPT_VERSION, "version", 0},
+ 	{OPT_VERBOSE, "verbose", 0},
+ 	{OPT_INFILE, "f", JAS_OPT_HASARG},
++	{OPT_DEBUG, "debug-level", JAS_OPT_HASARG},
+ 	{-1, 0, 0}
+ };
+ 
+@@ -126,6 +128,7 @@ int main(int argc, char **argv)
+ 	int numcmpts;
+ 	int verbose;
+ 	char *fmtname;
++	int debug;
+ 
+ 	if (jas_init()) {
+ 		abort();
+@@ -135,6 +138,7 @@ int main(int argc, char **argv)
+ 
+ 	infile = 0;
+ 	verbose = 0;
++	debug = 0;
+ 
+ 	/* Parse the command line options. */
+ 	while ((id = jas_getopt(argc, argv, opts)) >= 0) {
+@@ -146,6 +150,9 @@ int main(int argc, char **argv)
+ 			printf("%s\n", JAS_VERSION);
+ 			exit(EXIT_SUCCESS);
+ 			break;
++		case OPT_DEBUG:
++			debug = atoi(jas_optarg);
++			break;
+ 		case OPT_INFILE:
+ 			infile = jas_optarg;
+ 			break;
+@@ -156,6 +163,8 @@ int main(int argc, char **argv)
+ 		}
+ 	}
+ 
++	jas_setdbglevel(debug);
++
+ 	/* Open the image file. */
+ 	if (infile) {
+ 		/* The image is to be read from a file. */
+@@ -177,6 +186,7 @@ int main(int argc, char **argv)
+ 
+ 	/* Decode the image. */
+ 	if (!(image = jas_image_decode(instream, fmtid, 0))) {
++		jas_stream_close(instream);
+ 		fprintf(stderr, "cannot load image\n");
+ 		return EXIT_FAILURE;
+ 	}
+diff --git a/src/libjasper/bmp/bmp_dec.c b/src/libjasper/bmp/bmp_dec.c
+index 7a6dcb157483..6e7d8802cc7b 100644
+--- a/src/libjasper/bmp/bmp_dec.c
++++ b/src/libjasper/bmp/bmp_dec.c
+@@ -77,6 +77,7 @@
+ #include "jasper/jas_stream.h"
+ #include "jasper/jas_image.h"
+ #include "jasper/jas_malloc.h"
++#include "jasper/jas_debug.h"
+ 
+ #include "bmp_cod.h"
+ 
+@@ -122,12 +123,22 @@ jas_image_t *bmp_decode(jas_stream_t *in, char *optstr)
+ 		jas_eprintf("cannot get header\n");
+ 		return 0;
+ 	}
++	JAS_DBGLOG(1, (
++	  "BMP header: magic 0x%x; siz %d; res1 %d; res2 %d; off %d\n",
++	  hdr.magic, hdr.siz, hdr.reserved1, hdr.reserved2, hdr.off
++	  ));
+ 
+ 	/* Read the bitmap information. */
+ 	if (!(info = bmp_getinfo(in))) {
+ 		jas_eprintf("cannot get info\n");
+ 		return 0;
+ 	}
++	JAS_DBGLOG(1,
++	  ("BMP information: len %d; width %d; height %d; numplanes %d; "
++	  "depth %d; enctype %d; siz %d; hres %d; vres %d; numcolors %d; "
++	  "mincolors %d\n", info->len, info->width, info->height, info->numplanes,
++	  info->depth, info->enctype, info->siz, info->hres, info->vres,
++	  info->numcolors, info->mincolors));
+ 
+ 	/* Ensure that we support this type of BMP file. */
+ 	if (!bmp_issupported(&hdr, info)) {
+@@ -440,7 +451,7 @@ static int bmp_getint32(jas_stream_t *in, int_fast32_t *val)
+ 		if ((c = jas_stream_getc(in)) == EOF) {
+ 			return -1;
+ 		}
+-		v |= (c << 24);
++		v |= (JAS_CAST(uint_fast32_t, c) << 24);
+ 		if (--n <= 0) {
+ 			break;
+ 		}