|
|
94b862 |
Backport of the upstream commit:
|
|
|
94b862 |
|
|
|
94b862 |
From 2e82fa00466ae525339754bb3ab0a0474a31d4bd Mon Sep 17 00:00:00 2001
|
|
|
94b862 |
From: Michael Adams <mdadams@ece.uvic.ca>
|
|
|
94b862 |
Date: Wed, 19 Oct 2016 17:57:40 -0700
|
|
|
94b862 |
Subject: [PATCH] Fixed an integral type promotion problem by adding a
|
|
|
94b862 |
JAS_CAST. Modified the jpc_tsfb_synthesize function so that it will be a noop
|
|
|
94b862 |
for an empty sequence (in order to avoid dereferencing a null pointer).
|
|
|
94b862 |
|
|
|
94b862 |
diff -pruN jasper-1.900.1.orig/src/libjasper/include/jasper/jas_math.h jasper-1.900.1/src/libjasper/include/jasper/jas_math.h
|
|
|
94b862 |
--- jasper-1.900.1.orig/src/libjasper/include/jasper/jas_math.h 2017-03-31 14:08:18.000000000 +0200
|
|
|
94b862 |
+++ jasper-1.900.1/src/libjasper/include/jasper/jas_math.h 2017-03-31 14:09:06.000000000 +0200
|
|
|
94b862 |
@@ -115,6 +115,24 @@ extern "C" {
|
|
|
94b862 |
((1 << (n)) - 1)
|
|
|
94b862 |
|
|
|
94b862 |
/******************************************************************************\
|
|
|
94b862 |
+*
|
|
|
94b862 |
+\******************************************************************************/
|
|
|
94b862 |
+
|
|
|
94b862 |
+__attribute__((no_sanitize("undefined")))
|
|
|
94b862 |
+inline static jas_int_asr(int x, int n)
|
|
|
94b862 |
+{
|
|
|
94b862 |
+ assert(n >= 0);
|
|
|
94b862 |
+ return x >> n;
|
|
|
94b862 |
+}
|
|
|
94b862 |
+
|
|
|
94b862 |
+__attribute__((no_sanitize("undefined")))
|
|
|
94b862 |
+inline static jas_int_asl(int x, int n)
|
|
|
94b862 |
+{
|
|
|
94b862 |
+ assert(n >= 0);
|
|
|
94b862 |
+ return x << n;
|
|
|
94b862 |
+}
|
|
|
94b862 |
+
|
|
|
94b862 |
+/******************************************************************************\
|
|
|
94b862 |
* Safe integer arithmetic (i.e., with overflow checking).
|
|
|
94b862 |
\******************************************************************************/
|
|
|
94b862 |
|
|
|
94b862 |
diff -pruN jasper-1.900.1.orig/src/libjasper/include/jasper/jas_seq.h jasper-1.900.1/src/libjasper/include/jasper/jas_seq.h
|
|
|
94b862 |
--- jasper-1.900.1.orig/src/libjasper/include/jasper/jas_seq.h 2007-01-19 22:43:04.000000000 +0100
|
|
|
94b862 |
+++ jasper-1.900.1/src/libjasper/include/jasper/jas_seq.h 2017-03-31 14:09:06.000000000 +0200
|
|
|
94b862 |
@@ -154,6 +154,9 @@ typedef jas_matrix_t jas_seq_t;
|
|
|
94b862 |
#define jas_matrix_numcols(matrix) \
|
|
|
94b862 |
((matrix)->numcols_)
|
|
|
94b862 |
|
|
|
94b862 |
+#define jas_matrix_size(matrix) \
|
|
|
94b862 |
+ (jas_matrix_width(matrix) * jas_matrix_height(matrix))
|
|
|
94b862 |
+
|
|
|
94b862 |
/* Get a matrix element. */
|
|
|
94b862 |
#define jas_matrix_get(matrix, i, j) \
|
|
|
94b862 |
((matrix)->rows_[i][j])
|
|
|
94b862 |
@@ -269,6 +272,8 @@ jas_matrix_t *jas_seq2d_create(int xstar
|
|
|
94b862 |
((s)->xstart_ = (x), (s)->ystart_ = (y), \
|
|
|
94b862 |
(s)->xend_ = (s)->xstart_ + (s)->numcols_, \
|
|
|
94b862 |
(s)->yend_ = (s)->ystart_ + (s)->numrows_)
|
|
|
94b862 |
+#define jas_seq2d_size(s) \
|
|
|
94b862 |
+ (jas_seq2d_width(s) * jas_seq2d_height(s))
|
|
|
94b862 |
|
|
|
94b862 |
void jas_seq2d_bindsub(jas_matrix_t *s, jas_matrix_t *s1, int xstart,
|
|
|
94b862 |
int ystart, int xend, int yend);
|
|
|
94b862 |
diff -pruN jasper-1.900.1.orig/src/libjasper/jpc/jpc_dec.c jasper-1.900.1/src/libjasper/jpc/jpc_dec.c
|
|
|
94b862 |
--- jasper-1.900.1.orig/src/libjasper/jpc/jpc_dec.c 2017-03-31 14:08:18.000000000 +0200
|
|
|
94b862 |
+++ jasper-1.900.1/src/libjasper/jpc/jpc_dec.c 2017-03-31 14:09:06.000000000 +0200
|
|
|
94b862 |
@@ -1805,6 +1805,13 @@ static void jpc_undo_roi(jas_matrix_t *x
|
|
|
94b862 |
bool warn;
|
|
|
94b862 |
uint_fast32_t mask;
|
|
|
94b862 |
|
|
|
94b862 |
+ if (roishift < 0) {
|
|
|
94b862 |
+ /* We could instead return an error here. */
|
|
|
94b862 |
+ /* I do not think it matters much. */
|
|
|
94b862 |
+ jas_eprintf("warning: forcing negative ROI shift to zero "
|
|
|
94b862 |
+ "(bitstream is probably corrupt)\n");
|
|
|
94b862 |
+ roishift = 0;
|
|
|
94b862 |
+ }
|
|
|
94b862 |
if (roishift == 0 && bgshift == 0) {
|
|
|
94b862 |
return;
|
|
|
94b862 |
}
|
|
|
94b862 |
@@ -1823,7 +1830,7 @@ static void jpc_undo_roi(jas_matrix_t *x
|
|
|
94b862 |
} else {
|
|
|
94b862 |
/* We are dealing with non-ROI (i.e., background) data. */
|
|
|
94b862 |
mag <<= bgshift;
|
|
|
94b862 |
- mask = (1 << numbps) - 1;
|
|
|
94b862 |
+ mask = (JAS_CAST(uint_fast32_t, 1) << numbps) - 1;
|
|
|
94b862 |
/* Perform a basic sanity check on the sample value. */
|
|
|
94b862 |
/* Some implementations write garbage in the unused
|
|
|
94b862 |
most-significant bit planes introduced by ROI shifting.
|
|
|
94b862 |
diff -pruN jasper-1.900.1.orig/src/libjasper/jpc/jpc_tsfb.c jasper-1.900.1/src/libjasper/jpc/jpc_tsfb.c
|
|
|
94b862 |
--- jasper-1.900.1.orig/src/libjasper/jpc/jpc_tsfb.c 2007-01-19 22:43:07.000000000 +0100
|
|
|
94b862 |
+++ jasper-1.900.1/src/libjasper/jpc/jpc_tsfb.c 2017-03-31 14:09:06.000000000 +0200
|
|
|
94b862 |
@@ -148,7 +148,8 @@ int jpc_tsfb_analyze2(jpc_tsfb_t *tsfb,
|
|
|
94b862 |
|
|
|
94b862 |
int jpc_tsfb_synthesize(jpc_tsfb_t *tsfb, jas_seq2d_t *a)
|
|
|
94b862 |
{
|
|
|
94b862 |
- return (tsfb->numlvls > 0) ? jpc_tsfb_synthesize2(tsfb,
|
|
|
94b862 |
+ return (tsfb->numlvls > 0 && jas_seq2d_size(a)) ?
|
|
|
94b862 |
+ jpc_tsfb_synthesize2(tsfb,
|
|
|
94b862 |
jas_seq2d_getref(a, jas_seq2d_xstart(a), jas_seq2d_ystart(a)),
|
|
|
94b862 |
jas_seq2d_xstart(a), jas_seq2d_ystart(a), jas_seq2d_width(a),
|
|
|
94b862 |
jas_seq2d_height(a), jas_seq2d_rowstep(a), tsfb->numlvls - 1) : 0;
|