94b862
Backport of the upstream commit:
94b862
94b862
From 44a524e367597af58d6265ae2014468b334d0309 Mon Sep 17 00:00:00 2001
94b862
From: Michael Adams <mdadams@ece.uvic.ca>
94b862
Date: Thu, 20 Oct 2016 07:34:32 -0700
94b862
Subject: [PATCH] The memory stream interface allows for a buffer size of zero.
94b862
 The case of a zero-sized buffer was not handled correctly, as it could lead
94b862
 to a double free. This problem has now been fixed (hopefully). One might ask
94b862
 whether a zero-sized buffer should be allowed at all, but this is a question
94b862
 for another day.
94b862
94b862
diff -pruN jasper-1.900.1.orig/src/libjasper/base/jas_stream.c jasper-1.900.1/src/libjasper/base/jas_stream.c
94b862
--- jasper-1.900.1.orig/src/libjasper/base/jas_stream.c	2017-03-24 13:23:23.000000000 +0100
94b862
+++ jasper-1.900.1/src/libjasper/base/jas_stream.c	2017-03-24 13:33:01.986069625 +0100
94b862
@@ -991,8 +991,8 @@ static int mem_resize(jas_stream_memobj_
94b862
 {
94b862
 	unsigned char *buf;
94b862
 
94b862
-	assert(m->buf_);
94b862
-	if (!(buf = jas_realloc(m->buf_, bufsize))) {
94b862
+	//assert(m->buf_);
94b862
+	if (!(buf = jas_realloc(m->buf_, bufsize)) && bufsize) {
94b862
 		return -1;
94b862
 	}
94b862
 	m->buf_ = buf;