CVE-2016-10248 (published 2017-03-15T14:59Z)

The jpc_tsfb_synthesize function in jpc_tsfb.c in JasPer before 1.900.9 allows remote attackers to cause a denial of service (NULL pointer dereference) via vectors involving an empty sequence.

Severity: MEDIUM
CVSS v2 base score: 5.0 (AV:N/AC:L/Au:N/C:N/I:N/A:P)
CVSS v3 base score: 7.5, HIGH (CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H)

Weakness information:
cwe_id: CWE-476
cwe_name: NULL Pointer Dereference
description: The product dereferences a pointer that it expects to be valid but is NULL.
extended_description: 
            
            
            
         
         

Fix information:
repo_url: https://github.com/mdadams/jasper
commit_details: repo_url: https://github.com/mdadams/jasper
author: Michael Adams
author_date: 2016-10-19 17:57:40-07:00
msg: Fixed an integral type promotion problem by adding a JAS_CAST.
Modified the jpc_tsfb_synthesize function so that it will be a noop for
an empty sequence (in order to avoid dereferencing a null pointer).
repository: repo_url: https://github.com/mdadams/jasper
repo_name: jasper-software/jasper
description: Official Repository for the JasPer Image Coding Toolkit
repo_language: C
owner: mdadams
file_changes: filename: jas_math.h
change_type: ModificationType.MODIFY
diff: @@ -112,6 +112,24 @@ extern "C" {
 #define	JAS_ONES(n) \
   ((1 << (n)) - 1)
 
+/******************************************************************************\
+*
+\******************************************************************************/
+
+__attribute__((no_sanitize("undefined")))
+inline static jas_int_asr(int x, int n)
+{
+	assert(n >= 0);
+	return x >> n;
+}
+
+__attribute__((no_sanitize("undefined")))
+inline static jas_int_asl(int x, int n)
+{
+	assert(n >= 0);
+	return x << n;
+}
+
 /******************************************************************************\
 * Safe integer arithmetic (i.e., with overflow checking).
 \******************************************************************************/

programming_language: C
filename: jas_seq.h
change_type: ModificationType.MODIFY
diff: @@ -154,6 +154,9 @@ typedef jas_matrix_t jas_seq_t;
 #define jas_matrix_numcols(matrix) \
 	((matrix)->numcols_)
 
+#define jas_matrix_size(matrix) \
+	(jas_matrix_width(matrix) * jas_matrix_height(matrix))
+
 /* Get a matrix element. */
 #define jas_matrix_get(matrix, i, j) \
 	((matrix)->rows_[i][j])
@@ -269,6 +272,8 @@ jas_matrix_t *jas_seq2d_create(int xstart, int ystart, int xend, int yend);
 	((s)->xstart_ = (x), (s)->ystart_ = (y), \
 	  (s)->xend_ = (s)->xstart_ + (s)->numcols_, \
 	  (s)->yend_ = (s)->ystart_ + (s)->numrows_)
+#define jas_seq2d_size(s) \
+	(jas_seq2d_width(s) * jas_seq2d_height(s))
 
 void jas_seq2d_bindsub(jas_matrix_t *s, jas_matrix_t *s1, int xstart,
   int ystart, int xend, int yend);

programming_language: C
filename: jpc_dec.c
change_type: ModificationType.MODIFY
diff: @@ -1838,6 +1838,13 @@ static void jpc_undo_roi(jas_matrix_t *x, int roishift, int bgshift, int numbps)
 	bool warn;
 	uint_fast32_t mask;
 
+	if (roishift < 0) {
+		/* We could instead return an error here. */
+		/* I do not think it matters much. */
+		jas_eprintf("warning: forcing negative ROI shift to zero "
+		  "(bitstream is probably corrupt)\n");
+		roishift = 0;
+	}
 	if (roishift == 0 && bgshift == 0) {
 		return;
 	}
@@ -1856,7 +1863,7 @@ static void jpc_undo_roi(jas_matrix_t *x, int roishift, int bgshift, int numbps)
 			} else {
 				/* We are dealing with non-ROI (i.e., background) data. */
 				mag <<= bgshift;
-				mask = (1 << numbps) - 1;
+				mask = (JAS_CAST(uint_fast32_t, 1) << numbps) - 1;
 				/* Perform a basic sanity check on the sample value. */
 				/* Some implementations write garbage in the unused
 				  most-significant bit planes introduced by ROI shifting.

programming_language: C
filename: jpc_tsfb.c
change_type: ModificationType.MODIFY
diff: @@ -148,7 +148,8 @@ int jpc_tsfb_analyze2(jpc_tsfb_t *tsfb, int *a, int xstart, int ystart,
 
 int jpc_tsfb_synthesize(jpc_tsfb_t *tsfb, jas_seq2d_t *a)
 {
-	return (tsfb->numlvls > 0) ? jpc_tsfb_synthesize2(tsfb,
+	return (tsfb->numlvls > 0 && jas_seq2d_size(a)) ?
+	  jpc_tsfb_synthesize2(tsfb,
 	  jas_seq2d_getref(a, jas_seq2d_xstart(a), jas_seq2d_ystart(a)),
 	  jas_seq2d_xstart(a), jas_seq2d_ystart(a), jas_seq2d_width(a),
 	  jas_seq2d_height(a), jas_seq2d_rowstep(a), tsfb->numlvls - 1) : 0;

programming_language: C