Skip to content

Commit

Permalink
The memory stream interface allows for a buffer size of zero.
Browse files Browse the repository at this point in the history
The case of a zero-sized buffer was not handled correctly, as it could
lead to a double free.
This problem has now been fixed (hopefully).
One might ask whether a zero-sized buffer should be allowed at all,
but this is a question for another day.
  • Loading branch information
mdadams committed Oct 20, 2016
1 parent efb88eb commit 44a524e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/libjasper/base/jas_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,9 +993,10 @@ static int mem_resize(jas_stream_memobj_t *m, int bufsize)
{
unsigned char *buf;

assert(m->buf_);
//assert(m->buf_);
assert(bufsize >= 0);
if (!(buf = jas_realloc2(m->buf_, bufsize, sizeof(unsigned char)))) {
if (!(buf = jas_realloc2(m->buf_, bufsize, sizeof(unsigned char))) &&
bufsize) {
return -1;
}
m->buf_ = buf;
Expand Down

0 comments on commit 44a524e

Please sign in to comment.