1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
7 SDESC[standard]= Implementation JPEG-2000 standard codec
8 HOMEPAGE= http://www.ece.uvic.ca/~frodo/jasper/
12 SITES[main]= http://www.ece.uvic.ca/~mdadams/jasper/software/
13 ftp://ftp.imagemagick.org/pub/ImageMagick/delegates/
14 DISTFILE[1]= jasper-1.900.1.zip:main
16 SPKGS[standard]= complete
20 OPTIONS_AVAILABLE= none
21 OPTIONS_STANDARD= none
23 BUILDRUN_DEPENDS= freeglut:primary:standard
25 USES= jpeg libtool:keepla fbsd10fix
26 XORG_COMPONENTS= x11 xext xi xmu
28 FPC_EQUIVALENT= graphics/jasper
31 CONFIGURE_ARGS= --enable-shared
35 INSTALL_TARGET= install-strip
38 ${MKDIR} ${STAGEDIR}${STD_DOCDIR}/
39 ${INSTALL_DATA} ${WRKSRC}/doc/* ${STAGEDIR}${STD_DOCDIR}/
41 [FILE:1040:descriptions/desc.primary]
42 The JasPer Project is an open-source initiative to provide a free
43 software-based reference implementation of the codec specified in the
44 JPEG-2000 Part-1 standard (i.e., ISO/IEC 15444-1). This project was
45 started as a collaborative effort between Image Power, Inc. and the
46 University of British Columbia. Presently, the ongoing maintenance and
47 development of the JasPer software is being coordinated by its principal
48 author, Michael Adams, who is affiliated with the Digital Signal
49 Processing Group (DSPG) in the Department of Electrical and Computer
50 Engineering at the University of Victoria.
52 JasPer includes a software-based implementation of the codec specified in
53 the JPEG-2000 Part-1 standard (i.e., ISO/IEC 15444-1). The JasPer software
54 is written in the C programming language. More details about this software
55 can be found in the JasPer Software Reference Manual.
57 The JasPer software has been included in the JPEG-2000 Part-5 standard
58 (i.e., ISO/IEC 15444-5), as an official reference implementation of the
59 JPEG-2000 Part-1 codec.
63 6b905a9c2aca2e275544212666eefc4eb44d95d0a57e4305457b407fe63f9494 1415752 jasper-1.900.1.zip
66 [FILE:446:manifests/plist.primary]
106 [FILE:52:manifests/plist.docs]
113 [FILE:1002:patches/patch-atexit]
114 When compiling with gcc don't register jas_cleanup with atexit.
115 Instead, mark it as a destructor using a gcc-only extension.
117 This will avoid crashes, when an application, which has explicitly
118 dlclosed() libjasper, exits.
120 If a similar method exists for other compilers, it should be used
121 too. Or, maybe, something can be done with __cxa_atexit() here...
125 --- src/libjasper/include/jasper/jas_init.h 2007-01-19 16:43:04.000000000 -0500
126 +++ src/libjasper/include/jasper/jas_init.h 2007-08-05 11:42:41.000000000 -0400
131 +void jas_cleanup(void) __attribute__ ((destructor));
133 void jas_cleanup(void);
137 --- src/libjasper/base/jas_init.c 2007-01-19 16:43:05.000000000 -0500
138 +++ src/libjasper/base/jas_init.c 2007-08-05 11:44:00.000000000 -0400
140 as it ensures that the JasPer exit handler is called before the
141 debug memory allocator exit handler. */
142 - atexit(jas_cleanup);
147 [FILE:377:patches/patch-bmp_dec.c]
148 --- src/libjasper/bmp/bmp_dec.c.orig 2007-01-19 22:43:07.000000000 +0100
149 +++ src/libjasper/bmp/bmp_dec.c 2013-04-17 22:32:23.000000000 +0200
153 if (info->numcolors > 0) {
154 - if (!(info->palents = jas_malloc(info->numcolors *
155 + if (!(info->palents = jas_malloc2(info->numcolors,
156 sizeof(bmp_palent_t)))) {
157 bmp_info_destroy(info);
161 [FILE:1580:patches/patch-jas_cm.c]
162 --- src/libjasper/base/jas_cm.c.orig 2007-01-19 22:43:05.000000000 +0100
163 +++ src/libjasper/base/jas_cm.c 2013-04-17 22:32:23.000000000 +0200
167 assert(n >= pxformseq->numpxforms);
168 - p = (!pxformseq->pxforms) ? jas_malloc(n * sizeof(jas_cmpxform_t *)) :
169 - jas_realloc(pxformseq->pxforms, n * sizeof(jas_cmpxform_t *));
170 + p = jas_realloc2(pxformseq->pxforms, n, sizeof(jas_cmpxform_t *));
174 @@ -889,13 +888,13 @@
175 jas_cmshapmatlut_cleanup(lut);
176 if (curv->numents == 0) {
178 - if (!(lut->data = jas_malloc(lut->size * sizeof(jas_cmreal_t))))
179 + if (!(lut->data = jas_malloc2(lut->size, sizeof(jas_cmreal_t))))
183 } else if (curv->numents == 1) {
185 - if (!(lut->data = jas_malloc(lut->size * sizeof(jas_cmreal_t))))
186 + if (!(lut->data = jas_malloc2(lut->size, sizeof(jas_cmreal_t))))
188 gamma = curv->ents[0] / 256.0;
189 for (i = 0; i < lut->size; ++i) {
193 lut->size = curv->numents;
194 - if (!(lut->data = jas_malloc(lut->size * sizeof(jas_cmreal_t))))
195 + if (!(lut->data = jas_malloc2(lut->size, sizeof(jas_cmreal_t))))
197 for (i = 0; i < lut->size; ++i) {
198 lut->data[i] = curv->ents[i] / 65535.0;
203 - if (!(invlut->data = jas_malloc(n * sizeof(jas_cmreal_t))))
204 + if (!(invlut->data = jas_malloc2(n, sizeof(jas_cmreal_t))))
207 for (i = 0; i < invlut->size; ++i) {
210 [FILE:4701:patches/patch-jas_icc.c]
211 --- src/libjasper/base/jas_icc.c.orig 2007-01-19 22:43:05.000000000 +0100
212 +++ src/libjasper/base/jas_icc.c 2016-02-20 13:49:45.521860000 +0100
214 jas_icctagtab_t *tagtab;
216 tagtab = &prof->tagtab;
217 - if (!(tagtab->ents = jas_malloc(prof->attrtab->numattrs *
218 + if (!(tagtab->ents = jas_malloc2(prof->attrtab->numattrs,
219 sizeof(jas_icctagtabent_t))))
221 tagtab->numents = prof->attrtab->numattrs;
224 if (jas_iccgetuint32(in, &tagtab->numents))
226 - if (!(tagtab->ents = jas_malloc(tagtab->numents *
227 + if (!(tagtab->ents = jas_malloc2(tagtab->numents,
228 sizeof(jas_icctagtabent_t))))
230 tagtabent = tagtab->ents;
233 jas_iccattr_t *newattrs;
234 assert(maxents >= tab->numattrs);
235 - newattrs = tab->attrs ? jas_realloc(tab->attrs, maxents *
236 - sizeof(jas_iccattr_t)) : jas_malloc(maxents * sizeof(jas_iccattr_t));
237 + newattrs = jas_realloc2(tab->attrs, maxents, sizeof(jas_iccattr_t));
240 tab->attrs = newattrs;
243 if (jas_iccgetuint32(in, &curv->numents))
245 - if (!(curv->ents = jas_malloc(curv->numents * sizeof(jas_iccuint16_t))))
246 + if (!(curv->ents = jas_malloc2(curv->numents, sizeof(jas_iccuint16_t))))
248 for (i = 0; i < curv->numents; ++i) {
249 if (jas_iccgetuint16(in, &curv->ents[i]))
250 @@ -1011,7 +1010,6 @@
254 - jas_icccurv_destroy(attrval);
258 @@ -1100,7 +1098,7 @@
259 if (jas_iccgetuint32(in, &txtdesc->uclangcode) ||
260 jas_iccgetuint32(in, &txtdesc->uclen))
262 - if (!(txtdesc->ucdata = jas_malloc(txtdesc->uclen * 2)))
263 + if (!(txtdesc->ucdata = jas_malloc2(txtdesc->uclen, 2)))
265 if (jas_stream_read(in, txtdesc->ucdata, txtdesc->uclen * 2) !=
266 JAS_CAST(int, txtdesc->uclen * 2))
267 @@ -1129,7 +1127,6 @@
271 - jas_icctxtdesc_destroy(attrval);
275 @@ -1208,8 +1205,6 @@
280 - jas_free(txt->string);
284 @@ -1292,17 +1287,17 @@
285 jas_iccgetuint16(in, &lut8->numouttabents))
287 clutsize = jas_iccpowi(lut8->clutlen, lut8->numinchans) * lut8->numoutchans;
288 - if (!(lut8->clut = jas_malloc(clutsize * sizeof(jas_iccuint8_t))) ||
289 - !(lut8->intabsbuf = jas_malloc(lut8->numinchans *
290 - lut8->numintabents * sizeof(jas_iccuint8_t))) ||
291 - !(lut8->intabs = jas_malloc(lut8->numinchans *
292 + if (!(lut8->clut = jas_malloc2(clutsize, sizeof(jas_iccuint8_t))) ||
293 + !(lut8->intabsbuf = jas_malloc3(lut8->numinchans,
294 + lut8->numintabents, sizeof(jas_iccuint8_t))) ||
295 + !(lut8->intabs = jas_malloc2(lut8->numinchans,
296 sizeof(jas_iccuint8_t *))))
298 for (i = 0; i < lut8->numinchans; ++i)
299 lut8->intabs[i] = &lut8->intabsbuf[i * lut8->numintabents];
300 - if (!(lut8->outtabsbuf = jas_malloc(lut8->numoutchans *
301 - lut8->numouttabents * sizeof(jas_iccuint8_t))) ||
302 - !(lut8->outtabs = jas_malloc(lut8->numoutchans *
303 + if (!(lut8->outtabsbuf = jas_malloc3(lut8->numoutchans,
304 + lut8->numouttabents, sizeof(jas_iccuint8_t))) ||
305 + !(lut8->outtabs = jas_malloc2(lut8->numoutchans,
306 sizeof(jas_iccuint8_t *))))
308 for (i = 0; i < lut8->numoutchans; ++i)
309 @@ -1330,7 +1325,6 @@
313 - jas_icclut8_destroy(attrval);
317 @@ -1461,17 +1455,17 @@
318 jas_iccgetuint16(in, &lut16->numouttabents))
320 clutsize = jas_iccpowi(lut16->clutlen, lut16->numinchans) * lut16->numoutchans;
321 - if (!(lut16->clut = jas_malloc(clutsize * sizeof(jas_iccuint16_t))) ||
322 - !(lut16->intabsbuf = jas_malloc(lut16->numinchans *
323 - lut16->numintabents * sizeof(jas_iccuint16_t))) ||
324 - !(lut16->intabs = jas_malloc(lut16->numinchans *
325 + if (!(lut16->clut = jas_malloc2(clutsize, sizeof(jas_iccuint16_t))) ||
326 + !(lut16->intabsbuf = jas_malloc3(lut16->numinchans,
327 + lut16->numintabents, sizeof(jas_iccuint16_t))) ||
328 + !(lut16->intabs = jas_malloc2(lut16->numinchans,
329 sizeof(jas_iccuint16_t *))))
331 for (i = 0; i < lut16->numinchans; ++i)
332 lut16->intabs[i] = &lut16->intabsbuf[i * lut16->numintabents];
333 - if (!(lut16->outtabsbuf = jas_malloc(lut16->numoutchans *
334 - lut16->numouttabents * sizeof(jas_iccuint16_t))) ||
335 - !(lut16->outtabs = jas_malloc(lut16->numoutchans *
336 + if (!(lut16->outtabsbuf = jas_malloc3(lut16->numoutchans,
337 + lut16->numouttabents, sizeof(jas_iccuint16_t))) ||
338 + !(lut16->outtabs = jas_malloc2(lut16->numoutchans,
339 sizeof(jas_iccuint16_t *))))
341 for (i = 0; i < lut16->numoutchans; ++i)
342 @@ -1499,7 +1493,6 @@
346 - jas_icclut16_destroy(attrval);
352 [FILE:1187:patches/patch-jas_image.c]
353 --- src/libjasper/base/jas_image.c.orig 2007-01-19 22:43:05.000000000 +0100
354 +++ src/libjasper/base/jas_image.c 2016-02-20 13:59:00.999124000 +0100
356 image->inmem_ = true;
358 /* Allocate memory for the per-component information. */
359 - if (!(image->cmpts_ = jas_malloc(image->maxcmpts_ *
360 + if (!(image->cmpts_ = jas_malloc2(image->maxcmpts_,
361 sizeof(jas_image_cmpt_t *)))) {
362 jas_image_destroy(image);
368 + if (!data->rows_) {
372 if (jas_matrix_numrows(data) != height || jas_matrix_numcols(data) != width) {
373 if (jas_matrix_resize(data, height, width)) {
379 + if (!data->rows_) {
383 if (jas_matrix_numrows(data) != height || jas_matrix_numcols(data) != width) {
387 jas_image_cmpt_t **newcmpts;
390 - newcmpts = (!image->cmpts_) ? jas_malloc(maxcmpts * sizeof(jas_image_cmpt_t *)) :
391 - jas_realloc(image->cmpts_, maxcmpts * sizeof(jas_image_cmpt_t *));
392 + newcmpts = jas_realloc2(image->cmpts_, maxcmpts, sizeof(jas_image_cmpt_t *));
398 [FILE:1347:patches/patch-jas_malloc.c]
399 --- src/libjasper/base/jas_malloc.c.orig 2007-01-19 22:43:05.000000000 +0100
400 +++ src/libjasper/base/jas_malloc.c 2013-04-17 22:43:09.000000000 +0200
403 /* We need the prototype for memset. */
409 #include "jasper/jas_malloc.h"
411 @@ -113,19 +116,51 @@
413 void *jas_realloc(void *ptr, size_t size)
415 - return realloc(ptr, size);
416 + return ptr ? realloc(ptr, size) : malloc(size);
419 void *jas_calloc(size_t nmemb, size_t size)
423 + ptr = jas_malloc2(nmemb, size);
425 + memset(ptr, 0, nmemb*size);
429 +void *jas_realloc2(void *ptr, size_t nmemb, size_t size)
432 + return jas_malloc2(nmemb, size);
433 + if (nmemb && SIZE_MAX / nmemb < size) {
437 + return jas_realloc(ptr, nmemb * size);
441 +void *jas_malloc2(size_t nmemb, size_t size)
443 + if (nmemb && SIZE_MAX / nmemb < size) {
448 + return jas_malloc(nmemb * size);
451 +void *jas_malloc3(size_t a, size_t b, size_t c)
455 - if (!(ptr = jas_malloc(n * sizeof(char)))) {
458 + if (a && SIZE_MAX / a < b) {
465 + return jas_malloc2(a*b, c);
471 [FILE:860:patches/patch-jas_malloc.h]
472 --- src/libjasper/include/jasper/jas_malloc.h.orig 2007-01-19 22:43:04.000000000 +0100
473 +++ src/libjasper/include/jasper/jas_malloc.h 2013-04-17 22:16:16.000000000 +0200
475 #define jas_free MEMFREE
476 #define jas_realloc MEMREALLOC
477 #define jas_calloc MEMCALLOC
478 +#define jas_malloc2(a, b) MEMALLOC((a)*(b))
479 +#define jas_malloc3(a, b, c) MEMALLOC((a)*(b)*(c))
480 +#define jas_realloc2(p, a, b) MEMREALLOC((p), (a)*(b))
483 /******************************************************************************\
485 /* Allocate a block of memory and initialize the contents to zero. */
486 void *jas_calloc(size_t nmemb, size_t size);
488 +/* size-checked double allocation .*/
489 +void *jas_malloc2(size_t, size_t);
491 +void *jas_malloc3(size_t, size_t, size_t);
493 +void *jas_realloc2(void *, size_t, size_t);
500 [FILE:2200:patches/patch-jas_seq.c]
501 --- src/libjasper/base/jas_seq.c.orig 2007-01-19 22:43:05.000000000 +0100
502 +++ src/libjasper/base/jas_seq.c 2016-02-20 13:59:01.014091000 +0100
504 matrix->datasize_ = numrows * numcols;
506 if (matrix->maxrows_ > 0) {
507 - if (!(matrix->rows_ = jas_malloc(matrix->maxrows_ *
508 + if (!(matrix->rows_ = jas_malloc2(matrix->maxrows_,
509 sizeof(jas_seqent_t *)))) {
510 jas_matrix_destroy(matrix);
515 if (matrix->datasize_ > 0) {
516 - if (!(matrix->data_ = jas_malloc(matrix->datasize_ *
517 + if (!(matrix->data_ = jas_malloc2(matrix->datasize_,
518 sizeof(jas_seqent_t)))) {
519 jas_matrix_destroy(matrix);
522 mat0->numrows_ = r1 - r0 + 1;
523 mat0->numcols_ = c1 - c0 + 1;
524 mat0->maxrows_ = mat0->numrows_;
525 - mat0->rows_ = jas_malloc(mat0->maxrows_ * sizeof(jas_seqent_t *));
526 + mat0->rows_ = jas_malloc2(mat0->maxrows_, sizeof(jas_seqent_t *));
527 for (i = 0; i < mat0->numrows_; ++i) {
528 mat0->rows_[i] = mat1->rows_[r0 + i] + c0;
534 + if (!matrix->rows_) {
538 rowstep = jas_matrix_rowstep(matrix);
539 for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
540 rowstart += rowstep) {
545 + if (!matrix->rows_) {
549 rowstep = jas_matrix_rowstep(matrix);
550 for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
551 rowstart += rowstep) {
556 + if (!matrix->rows_) {
561 rowstep = jas_matrix_rowstep(matrix);
562 for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
567 + if (!matrix->rows_) {
571 rowstep = jas_matrix_rowstep(matrix);
572 for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
573 rowstart += rowstep) {
578 + if (!matrix->rows_) {
582 rowstep = jas_matrix_rowstep(matrix);
583 for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
584 rowstart += rowstep) {
587 [FILE:2127:patches/patch-jas_stream.c]
588 --- src/libjasper/base/jas_stream.c.orig 2007-01-19 22:43:05.000000000 +0100
589 +++ src/libjasper/base/jas_stream.c 2015-08-29 08:07:01.000000000 +0200
591 static void jas_stream_destroy(jas_stream_t *stream);
592 static jas_stream_t *jas_stream_create(void);
593 static void jas_stream_initbuf(jas_stream_t *stream, int bufmode, char *buf,
597 static int mem_read(jas_stream_obj_t *obj, char *buf, int cnt);
598 static int mem_write(jas_stream_obj_t *obj, char *buf, int cnt);
603 -jas_stream_t *jas_stream_memopen(char *buf, int bufsize)
604 +jas_stream_t *jas_stream_memopen(char *buf, size_t bufsize)
606 jas_stream_t *stream;
607 jas_stream_memobj_t *obj;
608 @@ -361,15 +361,14 @@
612 - obj->pathname[0] = '\0';
613 + snprintf(obj->pathname, sizeof(obj->pathname), "/tmp/jasper.XXXXXX");
616 /* Choose a file name. */
617 - tmpnam(obj->pathname);
618 + obj->fd = mkstemp(obj->pathname);
620 /* Open the underlying file. */
621 - if ((obj->fd = open(obj->pathname, O_CREAT | O_EXCL | O_RDWR | O_TRUNC | O_BINARY,
622 - JAS_STREAM_PERMS)) < 0) {
624 jas_stream_destroy(stream);
631 - ret = vsprintf(buf, fmt, ap);
632 + ret = vsnprintf(buf, sizeof(buf), fmt, ap);
633 jas_stream_puts(stream, buf);
640 -char *jas_stream_gets(jas_stream_t *stream, char *buf, int bufsize)
641 +char *jas_stream_gets(jas_stream_t *stream, char *buf, size_t bufsize)
646 \******************************************************************************/
648 static void jas_stream_initbuf(jas_stream_t *stream, int bufmode, char *buf,
652 /* If this function is being called, the buffer should not have been
658 -static int mem_resize(jas_stream_memobj_t *m, int bufsize)
659 +static int mem_resize(jas_stream_memobj_t *m, size_t bufsize)
665 [FILE:1262:patches/patch-jas_stream.h]
666 --- src/libjasper/include/jasper/jas_stream.h.orig 2007-01-19 22:43:04.000000000 +0100
667 +++ src/libjasper/include/jasper/jas_stream.h 2015-08-29 07:54:41.000000000 +0200
671 /* The buffer size. */
675 /* The current position in the buffer. */
680 /* The allocated size of the buffer for holding file data. */
684 /* The length of the file. */
687 jas_stream_t *jas_stream_fopen(const char *filename, const char *mode);
689 /* Open a memory buffer as a stream. */
690 -jas_stream_t *jas_stream_memopen(char *buf, int bufsize);
691 +jas_stream_t *jas_stream_memopen(char *buf, size_t bufsize);
693 /* Open a file descriptor as a stream. */
694 jas_stream_t *jas_stream_fdopen(int fd, const char *mode);
696 int jas_stream_puts(jas_stream_t *stream, const char *s);
698 /* Read a line of input from a stream. */
699 -char *jas_stream_gets(jas_stream_t *stream, char *buf, int bufsize);
700 +char *jas_stream_gets(jas_stream_t *stream, char *buf, size_t bufsize);
702 /* Look at the next character to be read from a stream without actually
703 removing it from the stream. */
706 [FILE:562:patches/patch-jas_types.h]
707 --- src/libjasper/include/jasper/jas_types.h.orig 2007-01-19 22:43:04.000000000 +0100
708 +++ src/libjasper/include/jasper/jas_types.h 2016-02-20 13:49:45.555375000 +0100
709 @@ -179,13 +179,13 @@
712 #if !defined(INT_FAST64_MIN)
713 -typedef longlong int_fast64_t;
714 +typedef long long int_fast64_t;
715 #define INT_FAST64_MIN LLONG_MIN
716 #define INT_FAST64_MAX LLONG_MAX
719 #if !defined(UINT_FAST64_MAX)
720 -typedef ulonglong uint_fast64_t;
721 +typedef unsigned long long uint_fast64_t;
722 #define UINT_FAST64_MAX ULLONG_MAX
727 [FILE:2048:patches/patch-jp2_cod.c]
728 --- src/libjasper/jp2/jp2_cod.c.orig 2007-01-19 22:43:05.000000000 +0100
729 +++ src/libjasper/jp2/jp2_cod.c 2016-02-20 13:49:45.560559000 +0100
734 - if (!(box = jas_malloc(sizeof(jp2_box_t)))) {
735 + if (!(box = jas_calloc(1, sizeof(jp2_box_t)))) {
738 box->ops = &jp2_boxinfo_unk.ops;
740 jp2_bpcc_t *bpcc = &box->data.bpcc;
742 bpcc->numcmpts = box->datalen;
743 - if (!(bpcc->bpcs = jas_malloc(bpcc->numcmpts * sizeof(uint_fast8_t)))) {
744 + if (!(bpcc->bpcs = jas_malloc2(bpcc->numcmpts, sizeof(uint_fast8_t)))) {
747 for (i = 0; i < bpcc->numcmpts; ++i) {
751 colr->iccplen = box->datalen - 3;
752 - if (!(colr->iccp = jas_malloc(colr->iccplen * sizeof(uint_fast8_t)))) {
753 + if (!(colr->iccp = jas_malloc2(colr->iccplen, sizeof(uint_fast8_t)))) {
756 if (jas_stream_read(in, colr->iccp, colr->iccplen) != colr->iccplen) {
758 if (jp2_getuint16(in, &cdef->numchans)) {
761 - if (!(cdef->ents = jas_malloc(cdef->numchans * sizeof(jp2_cdefchan_t)))) {
762 + if (!(cdef->ents = jas_malloc2(cdef->numchans, sizeof(jp2_cdefchan_t)))) {
765 for (channo = 0; channo < cdef->numchans; ++channo) {
769 cmap->numchans = (box->datalen) / 4;
770 - if (!(cmap->ents = jas_malloc(cmap->numchans * sizeof(jp2_cmapent_t)))) {
771 + if (!(cmap->ents = jas_malloc2(cmap->numchans, sizeof(jp2_cmapent_t)))) {
774 for (i = 0; i < cmap->numchans; ++i) {
775 @@ -828,10 +828,10 @@
778 lutsize = pclr->numlutents * pclr->numchans;
779 - if (!(pclr->lutdata = jas_malloc(lutsize * sizeof(int_fast32_t)))) {
780 + if (!(pclr->lutdata = jas_malloc2(lutsize, sizeof(int_fast32_t)))) {
783 - if (!(pclr->bpc = jas_malloc(pclr->numchans * sizeof(uint_fast8_t)))) {
784 + if (!(pclr->bpc = jas_malloc2(pclr->numchans, sizeof(uint_fast8_t)))) {
787 for (i = 0; i < pclr->numchans; ++i) {
790 [FILE:1776:patches/patch-jp2_dec.c]
791 --- src/libjasper/jp2/jp2_dec.c.orig 2007-01-19 22:43:05.000000000 +0100
792 +++ src/libjasper/jp2/jp2_dec.c 2016-02-20 13:49:45.565514000 +0100
795 iccprof = jas_iccprof_createfrombuf(dec->colr->data.colr.iccp,
796 dec->colr->data.colr.iccplen);
799 + jas_eprintf("error: failed to parse ICC profile\n");
802 jas_iccprof_gethdr(iccprof, &icchdr);
803 jas_eprintf("ICC Profile CS %08x\n", icchdr.colorspc);
804 jas_image_setclrspc(dec->image, fromiccpcs(icchdr.colorspc));
808 /* Allocate space for the channel-number to component-number LUT. */
809 - if (!(dec->chantocmptlut = jas_malloc(dec->numchans * sizeof(uint_fast16_t)))) {
810 + if (!(dec->chantocmptlut = jas_malloc2(dec->numchans, sizeof(uint_fast16_t)))) {
811 jas_eprintf("error: no memory\n");
815 if (cmapent->map == JP2_CMAP_DIRECT) {
816 dec->chantocmptlut[channo] = channo;
817 } else if (cmapent->map == JP2_CMAP_PALETTE) {
818 - lutents = jas_malloc(pclrd->numlutents * sizeof(int_fast32_t));
819 + lutents = jas_malloc2(pclrd->numlutents, sizeof(int_fast32_t));
820 for (i = 0; i < pclrd->numlutents; ++i) {
821 lutents[i] = pclrd->lutdata[cmapent->pcol + i * pclrd->numchans];
824 /* Determine the type of each component. */
826 for (i = 0; i < dec->numchans; ++i) {
827 + /* Is the channel number reasonable? */
828 + if (dec->cdef->data.cdef.ents[i].channo >= dec->numchans) {
829 + jas_eprintf("error: invalid channel number in CDEF box\n");
832 jas_image_setcmpttype(dec->image,
833 dec->chantocmptlut[dec->cdef->data.cdef.ents[i].channo],
834 jp2_getct(jas_image_clrspc(dec->image),
837 [FILE:745:patches/patch-jp2_enc.c]
838 --- src/libjasper/jp2/jp2_enc.c.orig 2007-01-19 22:43:05.000000000 +0100
839 +++ src/libjasper/jp2/jp2_enc.c 2016-02-20 13:49:45.569962000 +0100
842 bpcc = &box->data.bpcc;
843 bpcc->numcmpts = jas_image_numcmpts(image);
844 - if (!(bpcc->bpcs = jas_malloc(bpcc->numcmpts *
845 + if (!(bpcc->bpcs = jas_malloc2(bpcc->numcmpts,
846 sizeof(uint_fast8_t)))) {
851 cdef = &box->data.cdef;
852 cdef->numchans = jas_image_numcmpts(image);
853 - cdef->ents = jas_malloc(cdef->numchans * sizeof(jp2_cdefchan_t));
854 + cdef->ents = jas_malloc2(cdef->numchans, sizeof(jp2_cdefchan_t));
855 for (i = 0; i < jas_image_numcmpts(image); ++i) {
856 cdefchanent = &cdef->ents[i];
857 cdefchanent->channo = i;
860 [FILE:3148:patches/patch-jpc_cs.c]
861 --- src/libjasper/jpc/jpc_cs.c.orig 2007-01-19 22:43:07.000000000 +0100
862 +++ src/libjasper/jpc/jpc_cs.c 2013-04-17 22:11:18.000000000 +0200
864 jpc_ms_dump(ms, stderr);
867 - if (JAS_CAST(ulong, jas_stream_tell(tmpstream)) != ms->len) {
868 + if (JAS_CAST(unsigned long, jas_stream_tell(tmpstream)) != ms->len) {
869 jas_eprintf("warning: trailing garbage in marker segment (%ld bytes)\n",
870 ms->len - jas_stream_tell(tmpstream));
873 !siz->tileheight || !siz->numcomps) {
876 - if (!(siz->comps = jas_malloc(siz->numcomps * sizeof(jpc_sizcomp_t)))) {
877 + if (!(siz->comps = jas_malloc2(siz->numcomps, sizeof(jpc_sizcomp_t)))) {
880 for (i = 0; i < siz->numcomps; ++i) {
884 compparms->numrlvls = compparms->numdlvls + 1;
885 + if (compparms->numrlvls > JPC_MAXRLVLS) {
886 + jpc_cox_destroycompparms(compparms);
890 for (i = 0; i < compparms->numrlvls; ++i) {
891 if (jpc_getuint8(in, &tmp)) {
893 compparms->numstepsizes = (len - n) / 2;
896 + if (compparms->numstepsizes > 3 * JPC_MAXRLVLS + 1) {
897 + jpc_qcx_destroycompparms(compparms);
900 if (compparms->numstepsizes > 0) {
901 - compparms->stepsizes = jas_malloc(compparms->numstepsizes *
902 + compparms->stepsizes = jas_malloc2(compparms->numstepsizes,
903 sizeof(uint_fast16_t));
904 assert(compparms->stepsizes);
905 for (i = 0; i < compparms->numstepsizes; ++i) {
906 @@ -1091,7 +1099,7 @@
908 ppm->len = ms->len - 1;
910 - if (!(ppm->data = jas_malloc(ppm->len * sizeof(unsigned char)))) {
911 + if (!(ppm->data = jas_malloc2(ppm->len, sizeof(unsigned char)))) {
914 if (JAS_CAST(uint, jas_stream_read(in, ppm->data, ppm->len)) != ppm->len) {
915 @@ -1160,7 +1168,7 @@
917 ppt->len = ms->len - 1;
919 - if (!(ppt->data = jas_malloc(ppt->len * sizeof(unsigned char)))) {
920 + if (!(ppt->data = jas_malloc2(ppt->len, sizeof(unsigned char)))) {
923 if (jas_stream_read(in, (char *) ppt->data, ppt->len) != JAS_CAST(int, ppt->len)) {
924 @@ -1223,7 +1231,7 @@
926 poc->numpchgs = (cstate->numcomps > 256) ? (ms->len / 9) :
928 - if (!(poc->pchgs = jas_malloc(poc->numpchgs * sizeof(jpc_pocpchg_t)))) {
929 + if (!(poc->pchgs = jas_malloc2(poc->numpchgs, sizeof(jpc_pocpchg_t)))) {
932 for (pchgno = 0, pchg = poc->pchgs; pchgno < poc->numpchgs; ++pchgno,
933 @@ -1328,7 +1336,7 @@
935 uint_fast16_t compno;
936 crg->numcomps = cstate->numcomps;
937 - if (!(crg->comps = jas_malloc(cstate->numcomps * sizeof(uint_fast16_t)))) {
938 + if (!(crg->comps = jas_malloc2(cstate->numcomps, sizeof(jpc_crgcomp_t)))) {
941 for (compno = 0, comp = crg->comps; compno < cstate->numcomps;
942 @@ -1467,7 +1475,7 @@
946 - if (!(unk->data = jas_malloc(ms->len * sizeof(unsigned char)))) {
947 + if (!(unk->data = jas_malloc2(ms->len, sizeof(unsigned char)))) {
950 if (jas_stream_read(in, (char *) unk->data, ms->len) != JAS_CAST(int, ms->len)) {
953 [FILE:5372:patches/patch-jpc_dec.c]
954 --- src/libjasper/jpc/jpc_dec.c.orig 2007-01-19 22:43:07.000000000 +0100
955 +++ src/libjasper/jpc/jpc_dec.c 2016-02-20 13:49:45.581508000 +0100
958 if (dec->state == JPC_MH) {
960 - compinfos = jas_malloc(dec->numcomps * sizeof(jas_image_cmptparm_t));
961 + compinfos = jas_malloc2(dec->numcomps, sizeof(jas_image_cmptparm_t));
963 for (cmptno = 0, cmpt = dec->cmpts, compinfo = compinfos;
964 cmptno < dec->numcomps; ++cmptno, ++cmpt, ++compinfo) {
966 dec->curtileendoff = 0;
969 - if (JAS_CAST(int, sot->tileno) > dec->numtiles) {
970 + if (JAS_CAST(int, sot->tileno) >= dec->numtiles) {
971 jas_eprintf("invalid tile number in SOT marker segment\n");
977 tcomp->numrlvls = ccp->numrlvls;
978 - if (!(tcomp->rlvls = jas_malloc(tcomp->numrlvls *
979 + if (!(tcomp->rlvls = jas_malloc2(tcomp->numrlvls,
980 sizeof(jpc_dec_rlvl_t)))) {
984 rlvl->cbgheightexpn);
986 rlvl->numbands = (!rlvlno) ? 1 : 3;
987 - if (!(rlvl->bands = jas_malloc(rlvl->numbands *
988 + if (!(rlvl->bands = jas_malloc2(rlvl->numbands,
989 sizeof(jpc_dec_band_t)))) {
994 assert(rlvl->numprcs);
996 - if (!(band->prcs = jas_malloc(rlvl->numprcs * sizeof(jpc_dec_prc_t)))) {
997 + if (!(band->prcs = jas_malloc2(rlvl->numprcs, sizeof(jpc_dec_prc_t)))) {
1002 if (!(prc->numimsbstagtree = jpc_tagtree_create(prc->numhcblks, prc->numvcblks))) {
1005 - if (!(prc->cblks = jas_malloc(prc->numcblks * sizeof(jpc_dec_cblk_t)))) {
1006 + if (!(prc->cblks = jas_malloc2(prc->numcblks, sizeof(jpc_dec_cblk_t)))) {
1010 @@ -1069,12 +1069,12 @@
1011 /* Apply an inverse intercomponent transform if necessary. */
1012 switch (tile->cp->mctid) {
1014 - assert(dec->numcomps == 3);
1015 + assert(dec->numcomps == 3 || dec->numcomps == 4);
1016 jpc_irct(tile->tcomps[0].data, tile->tcomps[1].data,
1017 tile->tcomps[2].data);
1020 - assert(dec->numcomps == 3);
1021 + assert(dec->numcomps == 3 || dec->numcomps == 4);
1022 jpc_iict(tile->tcomps[0].data, tile->tcomps[1].data,
1023 tile->tcomps[2].data);
1025 @@ -1181,7 +1181,7 @@
1029 - if (!(dec->cmpts = jas_malloc(dec->numcomps * sizeof(jpc_dec_cmpt_t)))) {
1030 + if (!(dec->cmpts = jas_malloc2(dec->numcomps, sizeof(jpc_dec_cmpt_t)))) {
1034 @@ -1204,7 +1204,7 @@
1035 dec->numhtiles = JPC_CEILDIV(dec->xend - dec->tilexoff, dec->tilewidth);
1036 dec->numvtiles = JPC_CEILDIV(dec->yend - dec->tileyoff, dec->tileheight);
1037 dec->numtiles = dec->numhtiles * dec->numvtiles;
1038 - if (!(dec->tiles = jas_malloc(dec->numtiles * sizeof(jpc_dec_tile_t)))) {
1039 + if (!(dec->tiles = jas_calloc(dec->numtiles, sizeof(jpc_dec_tile_t)))) {
1043 @@ -1228,7 +1228,7 @@
1044 tile->pkthdrstreampos = 0;
1047 - if (!(tile->tcomps = jas_malloc(dec->numcomps *
1048 + if (!(tile->tcomps = jas_calloc(dec->numcomps,
1049 sizeof(jpc_dec_tcomp_t)))) {
1052 @@ -1280,7 +1280,7 @@
1053 jpc_coc_t *coc = &ms->parms.coc;
1054 jpc_dec_tile_t *tile;
1056 - if (JAS_CAST(int, coc->compno) > dec->numcomps) {
1057 + if (JAS_CAST(int, coc->compno) >= dec->numcomps) {
1058 jas_eprintf("invalid component number in COC marker segment\n");
1061 @@ -1306,7 +1306,7 @@
1062 jpc_rgn_t *rgn = &ms->parms.rgn;
1063 jpc_dec_tile_t *tile;
1065 - if (JAS_CAST(int, rgn->compno) > dec->numcomps) {
1066 + if (JAS_CAST(int, rgn->compno) >= dec->numcomps) {
1067 jas_eprintf("invalid component number in RGN marker segment\n");
1070 @@ -1355,7 +1355,7 @@
1071 jpc_qcc_t *qcc = &ms->parms.qcc;
1072 jpc_dec_tile_t *tile;
1074 - if (JAS_CAST(int, qcc->compno) > dec->numcomps) {
1075 + if (JAS_CAST(int, qcc->compno) >= dec->numcomps) {
1076 jas_eprintf("invalid component number in QCC marker segment\n");
1079 @@ -1489,7 +1489,7 @@
1083 - if (!(cp->ccps = jas_malloc(cp->numcomps * sizeof(jpc_dec_ccp_t)))) {
1084 + if (!(cp->ccps = jas_malloc2(cp->numcomps, sizeof(jpc_dec_ccp_t)))) {
1087 if (!(cp->pchglist = jpc_pchglist_create())) {
1088 @@ -2048,7 +2048,7 @@
1090 streamlist->numstreams = 0;
1091 streamlist->maxstreams = 100;
1092 - if (!(streamlist->streams = jas_malloc(streamlist->maxstreams *
1093 + if (!(streamlist->streams = jas_malloc2(streamlist->maxstreams,
1094 sizeof(jas_stream_t *)))) {
1095 jas_free(streamlist);
1097 @@ -2068,8 +2068,8 @@
1098 /* Grow the array of streams if necessary. */
1099 if (streamlist->numstreams >= streamlist->maxstreams) {
1100 newmaxstreams = streamlist->maxstreams + 1024;
1101 - if (!(newstreams = jas_realloc(streamlist->streams,
1102 - (newmaxstreams + 1024) * sizeof(jas_stream_t *)))) {
1103 + if (!(newstreams = jas_realloc2(streamlist->streams,
1104 + (newmaxstreams + 1024), sizeof(jas_stream_t *)))) {
1107 for (i = streamlist->numstreams; i < streamlist->maxstreams; ++i) {
1108 @@ -2155,8 +2155,8 @@
1110 jpc_ppxstabent_t **newents;
1111 if (tab->maxents < maxents) {
1112 - newents = (tab->ents) ? jas_realloc(tab->ents, maxents *
1113 - sizeof(jpc_ppxstabent_t *)) : jas_malloc(maxents * sizeof(jpc_ppxstabent_t *));
1114 + newents = jas_realloc2(tab->ents, maxents,
1115 + sizeof(jpc_ppxstabent_t *));
1121 [FILE:3361:patches/patch-jpc_enc.c]
1122 --- src/libjasper/jpc/jpc_enc.c.orig 2007-01-19 22:43:07.000000000 +0100
1123 +++ src/libjasper/jpc/jpc_enc.c 2013-04-17 22:32:23.000000000 +0200
1125 vsteplcm *= jas_image_cmptvstep(image, cmptno);
1128 - if (!(cp->ccps = jas_malloc(cp->numcmpts * sizeof(jpc_enc_ccp_t)))) {
1129 + if (!(cp->ccps = jas_malloc2(cp->numcmpts, sizeof(jpc_enc_ccp_t)))) {
1132 for (cmptno = 0, ccp = cp->ccps; cmptno < JAS_CAST(int, cp->numcmpts); ++cmptno,
1135 if (ilyrrates && numilyrrates > 0) {
1136 tcp->numlyrs = numilyrrates + 1;
1137 - if (!(tcp->ilyrrates = jas_malloc((tcp->numlyrs - 1) *
1138 + if (!(tcp->ilyrrates = jas_malloc2((tcp->numlyrs - 1),
1139 sizeof(jpc_fix_t)))) {
1143 siz->tilewidth = cp->tilewidth;
1144 siz->tileheight = cp->tileheight;
1145 siz->numcomps = cp->numcmpts;
1146 - siz->comps = jas_malloc(siz->numcomps * sizeof(jpc_sizcomp_t));
1147 + siz->comps = jas_malloc2(siz->numcomps, sizeof(jpc_sizcomp_t));
1149 for (i = 0; i < JAS_CAST(int, cp->numcmpts); ++i) {
1150 siz->comps[i].prec = cp->ccps[i].prec;
1154 crg = &enc->mrk->parms.crg;
1155 - crg->comps = jas_malloc(crg->numcomps * sizeof(jpc_crgcomp_t));
1156 + crg->comps = jas_malloc2(crg->numcomps, sizeof(jpc_crgcomp_t));
1157 if (jpc_putms(enc->out, enc->cstate, enc->mrk)) {
1158 jas_eprintf("cannot write CRG marker\n");
1160 @@ -1955,7 +1955,7 @@
1161 tile->mctid = cp->tcp.mctid;
1163 tile->numlyrs = cp->tcp.numlyrs;
1164 - if (!(tile->lyrsizes = jas_malloc(tile->numlyrs *
1165 + if (!(tile->lyrsizes = jas_malloc2(tile->numlyrs,
1166 sizeof(uint_fast32_t)))) {
1169 @@ -1964,7 +1964,7 @@
1172 /* Allocate an array for the per-tile-component information. */
1173 - if (!(tile->tcmpts = jas_malloc(cp->numcmpts * sizeof(jpc_enc_tcmpt_t)))) {
1174 + if (!(tile->tcmpts = jas_malloc2(cp->numcmpts, sizeof(jpc_enc_tcmpt_t)))) {
1177 /* Initialize a few members critical for error recovery. */
1178 @@ -2110,7 +2110,7 @@
1179 jas_seq2d_ystart(tcmpt->data), jas_seq2d_xend(tcmpt->data),
1180 jas_seq2d_yend(tcmpt->data), bandinfos);
1182 - if (!(tcmpt->rlvls = jas_malloc(tcmpt->numrlvls * sizeof(jpc_enc_rlvl_t)))) {
1183 + if (!(tcmpt->rlvls = jas_malloc2(tcmpt->numrlvls, sizeof(jpc_enc_rlvl_t)))) {
1186 for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls;
1187 @@ -2213,7 +2213,7 @@
1188 rlvl->numvprcs = JPC_FLOORDIVPOW2(brprcbry - tlprctly, rlvl->prcheightexpn);
1189 rlvl->numprcs = rlvl->numhprcs * rlvl->numvprcs;
1191 - if (!(rlvl->bands = jas_malloc(rlvl->numbands * sizeof(jpc_enc_band_t)))) {
1192 + if (!(rlvl->bands = jas_malloc2(rlvl->numbands, sizeof(jpc_enc_band_t)))) {
1195 for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands;
1196 @@ -2290,7 +2290,7 @@
1197 band->synweight = bandinfo->synenergywt;
1200 - if (!(band->prcs = jas_malloc(rlvl->numprcs * sizeof(jpc_enc_prc_t)))) {
1201 + if (!(band->prcs = jas_malloc2(rlvl->numprcs, sizeof(jpc_enc_prc_t)))) {
1204 for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs; ++prcno,
1205 @@ -2422,7 +2422,7 @@
1209 - if (!(prc->cblks = jas_malloc(prc->numcblks * sizeof(jpc_enc_cblk_t)))) {
1210 + if (!(prc->cblks = jas_malloc2(prc->numcblks, sizeof(jpc_enc_cblk_t)))) {
1213 for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks;
1216 [FILE:505:patches/patch-jpc_mqdec.c]
1217 --- src/libjasper/jpc/jpc_mqdec.c.orig 2007-01-19 22:43:07.000000000 +0100
1218 +++ src/libjasper/jpc/jpc_mqdec.c 2013-04-17 22:32:23.000000000 +0200
1221 mqdec->maxctxs = maxctxs;
1222 /* Allocate memory for the per-context state information. */
1223 - if (!(mqdec->ctxs = jas_malloc(mqdec->maxctxs * sizeof(jpc_mqstate_t *)))) {
1224 + if (!(mqdec->ctxs = jas_malloc2(mqdec->maxctxs, sizeof(jpc_mqstate_t *)))) {
1227 /* Set the current context to the first context. */
1230 [FILE:437:patches/patch-jpc_mqenc.c]
1231 --- src/libjasper/jpc/jpc_mqenc.c.orig 2007-01-19 22:43:07.000000000 +0100
1232 +++ src/libjasper/jpc/jpc_mqenc.c 2013-04-17 22:32:23.000000000 +0200
1234 mqenc->maxctxs = maxctxs;
1236 /* Allocate memory for the per-context state information. */
1237 - if (!(mqenc->ctxs = jas_malloc(mqenc->maxctxs * sizeof(jpc_mqstate_t *)))) {
1238 + if (!(mqenc->ctxs = jas_malloc2(mqenc->maxctxs, sizeof(jpc_mqstate_t *)))) {
1244 [FILE:7955:patches/patch-jpc_qmfb.c]
1245 --- src/libjasper/jpc/jpc_qmfb.c.orig 2007-01-19 22:43:07.000000000 +0100
1246 +++ src/libjasper/jpc/jpc_qmfb.c 2016-02-20 13:56:19.711609000 +0100
1247 @@ -305,12 +305,8 @@
1248 void jpc_qmfb_split_row(jpc_fix_t *a, int numcols, int parity)
1251 - int bufsize = JPC_CEILDIVPOW2(numcols, 1);
1252 -#if !defined(HAVE_VLA)
1253 + size_t bufsize = JPC_CEILDIVPOW2(numcols, 1);
1254 jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE];
1256 - jpc_fix_t splitbuf[bufsize];
1258 jpc_fix_t *buf = splitbuf;
1259 register jpc_fix_t *srcptr;
1260 register jpc_fix_t *dstptr;
1261 @@ -318,15 +314,13 @@
1265 -#if !defined(HAVE_VLA)
1267 if (bufsize > QMFB_SPLITBUFSIZE) {
1268 - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
1269 + if (!(buf = jas_malloc2(bufsize, sizeof(jpc_fix_t)))) {
1270 /* We have no choice but to commit suicide in this case. */
1277 hstartcol = (numcols + 1 - parity) >> 1;
1278 @@ -360,12 +354,10 @@
1282 -#if !defined(HAVE_VLA)
1283 /* If the split buffer was allocated on the heap, free this memory. */
1284 if (buf != splitbuf) {
1291 @@ -373,12 +365,8 @@
1295 - int bufsize = JPC_CEILDIVPOW2(numrows, 1);
1296 -#if !defined(HAVE_VLA)
1297 + size_t bufsize = JPC_CEILDIVPOW2(numrows, 1);
1298 jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE];
1300 - jpc_fix_t splitbuf[bufsize];
1302 jpc_fix_t *buf = splitbuf;
1303 register jpc_fix_t *srcptr;
1304 register jpc_fix_t *dstptr;
1305 @@ -386,15 +374,13 @@
1309 -#if !defined(HAVE_VLA)
1311 if (bufsize > QMFB_SPLITBUFSIZE) {
1312 - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
1313 + if (!(buf = jas_malloc2(bufsize, sizeof(jpc_fix_t)))) {
1314 /* We have no choice but to commit suicide in this case. */
1321 hstartcol = (numrows + 1 - parity) >> 1;
1322 @@ -428,12 +414,10 @@
1326 -#if !defined(HAVE_VLA)
1327 /* If the split buffer was allocated on the heap, free this memory. */
1328 if (buf != splitbuf) {
1335 @@ -441,12 +425,8 @@
1339 - int bufsize = JPC_CEILDIVPOW2(numrows, 1);
1340 -#if !defined(HAVE_VLA)
1341 + size_t bufsize = JPC_CEILDIVPOW2(numrows, 1);
1342 jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE * JPC_QMFB_COLGRPSIZE];
1344 - jpc_fix_t splitbuf[bufsize * JPC_QMFB_COLGRPSIZE];
1346 jpc_fix_t *buf = splitbuf;
1349 @@ -457,15 +437,13 @@
1353 -#if !defined(HAVE_VLA)
1355 if (bufsize > QMFB_SPLITBUFSIZE) {
1356 - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
1357 + if (!(buf = jas_malloc2(bufsize, sizeof(jpc_fix_t)))) {
1358 /* We have no choice but to commit suicide in this case. */
1365 hstartcol = (numrows + 1 - parity) >> 1;
1366 @@ -517,12 +495,10 @@
1370 -#if !defined(HAVE_VLA)
1371 /* If the split buffer was allocated on the heap, free this memory. */
1372 if (buf != splitbuf) {
1379 @@ -530,12 +506,8 @@
1380 int stride, int parity)
1383 - int bufsize = JPC_CEILDIVPOW2(numrows, 1);
1384 -#if !defined(HAVE_VLA)
1385 + size_t bufsize = JPC_CEILDIVPOW2(numrows, 1);
1386 jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE * JPC_QMFB_COLGRPSIZE];
1388 - jpc_fix_t splitbuf[bufsize * numcols];
1390 jpc_fix_t *buf = splitbuf;
1393 @@ -546,15 +518,13 @@
1397 -#if !defined(HAVE_VLA)
1399 if (bufsize > QMFB_SPLITBUFSIZE) {
1400 - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
1401 + if (!(buf = jas_malloc2(bufsize, sizeof(jpc_fix_t)))) {
1402 /* We have no choice but to commit suicide in this case. */
1409 hstartcol = (numrows + 1 - parity) >> 1;
1410 @@ -606,39 +576,31 @@
1414 -#if !defined(HAVE_VLA)
1415 /* If the split buffer was allocated on the heap, free this memory. */
1416 if (buf != splitbuf) {
1423 void jpc_qmfb_join_row(jpc_fix_t *a, int numcols, int parity)
1426 - int bufsize = JPC_CEILDIVPOW2(numcols, 1);
1427 -#if !defined(HAVE_VLA)
1428 + size_t bufsize = JPC_CEILDIVPOW2(numcols, 1);
1429 jpc_fix_t joinbuf[QMFB_JOINBUFSIZE];
1431 - jpc_fix_t joinbuf[bufsize];
1433 jpc_fix_t *buf = joinbuf;
1434 register jpc_fix_t *srcptr;
1435 register jpc_fix_t *dstptr;
1439 -#if !defined(HAVE_VLA)
1440 /* Allocate memory for the join buffer from the heap. */
1441 if (bufsize > QMFB_JOINBUFSIZE) {
1442 - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
1443 + if (!(buf = jas_malloc2(bufsize, sizeof(jpc_fix_t)))) {
1444 /* We have no choice but to commit suicide. */
1450 hstartcol = (numcols + 1 - parity) >> 1;
1452 @@ -670,12 +632,10 @@
1456 -#if !defined(HAVE_VLA)
1457 /* If the join buffer was allocated on the heap, free this memory. */
1458 if (buf != joinbuf) {
1465 @@ -683,27 +643,21 @@
1469 - int bufsize = JPC_CEILDIVPOW2(numrows, 1);
1470 -#if !defined(HAVE_VLA)
1471 + size_t bufsize = JPC_CEILDIVPOW2(numrows, 1);
1472 jpc_fix_t joinbuf[QMFB_JOINBUFSIZE];
1474 - jpc_fix_t joinbuf[bufsize];
1476 jpc_fix_t *buf = joinbuf;
1477 register jpc_fix_t *srcptr;
1478 register jpc_fix_t *dstptr;
1482 -#if !defined(HAVE_VLA)
1483 /* Allocate memory for the join buffer from the heap. */
1484 if (bufsize > QMFB_JOINBUFSIZE) {
1485 - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
1486 + if (!(buf = jas_malloc2(bufsize, sizeof(jpc_fix_t)))) {
1487 /* We have no choice but to commit suicide. */
1493 hstartcol = (numrows + 1 - parity) >> 1;
1495 @@ -735,12 +689,10 @@
1499 -#if !defined(HAVE_VLA)
1500 /* If the join buffer was allocated on the heap, free this memory. */
1501 if (buf != joinbuf) {
1508 @@ -748,12 +700,8 @@
1512 - int bufsize = JPC_CEILDIVPOW2(numrows, 1);
1513 -#if !defined(HAVE_VLA)
1514 + size_t bufsize = JPC_CEILDIVPOW2(numrows, 1);
1515 jpc_fix_t joinbuf[QMFB_JOINBUFSIZE * JPC_QMFB_COLGRPSIZE];
1517 - jpc_fix_t joinbuf[bufsize * JPC_QMFB_COLGRPSIZE];
1519 jpc_fix_t *buf = joinbuf;
1522 @@ -763,15 +711,13 @@
1526 -#if !defined(HAVE_VLA)
1527 /* Allocate memory for the join buffer from the heap. */
1528 if (bufsize > QMFB_JOINBUFSIZE) {
1529 - if (!(buf = jas_malloc(bufsize * JPC_QMFB_COLGRPSIZE * sizeof(jpc_fix_t)))) {
1530 + if (!(buf = jas_malloc2(bufsize, JPC_QMFB_COLGRPSIZE * sizeof(jpc_fix_t)))) {
1531 /* We have no choice but to commit suicide. */
1537 hstartcol = (numrows + 1 - parity) >> 1;
1539 @@ -821,12 +767,10 @@
1540 srcptr += JPC_QMFB_COLGRPSIZE;
1543 -#if !defined(HAVE_VLA)
1544 /* If the join buffer was allocated on the heap, free this memory. */
1545 if (buf != joinbuf) {
1552 @@ -834,12 +778,8 @@
1553 int stride, int parity)
1556 - int bufsize = JPC_CEILDIVPOW2(numrows, 1);
1557 -#if !defined(HAVE_VLA)
1558 + size_t bufsize = JPC_CEILDIVPOW2(numrows, 1);
1559 jpc_fix_t joinbuf[QMFB_JOINBUFSIZE * JPC_QMFB_COLGRPSIZE];
1561 - jpc_fix_t joinbuf[bufsize * numcols];
1563 jpc_fix_t *buf = joinbuf;
1566 @@ -849,15 +789,13 @@
1570 -#if !defined(HAVE_VLA)
1571 /* Allocate memory for the join buffer from the heap. */
1572 if (bufsize > QMFB_JOINBUFSIZE) {
1573 - if (!(buf = jas_malloc(bufsize * numcols * sizeof(jpc_fix_t)))) {
1574 + if (!(buf = jas_malloc3(bufsize, numcols, sizeof(jpc_fix_t)))) {
1575 /* We have no choice but to commit suicide. */
1581 hstartcol = (numrows + 1 - parity) >> 1;
1583 @@ -907,12 +845,10 @@
1587 -#if !defined(HAVE_VLA)
1588 /* If the join buffer was allocated on the heap, free this memory. */
1589 if (buf != joinbuf) {
1598 [FILE:466:patches/patch-jpc_t1enc.c]
1599 --- src/libjasper/jpc/jpc_t1enc.c.orig 2007-01-19 22:43:07.000000000 +0100
1600 +++ src/libjasper/jpc/jpc_t1enc.c 2013-04-17 22:32:23.000000000 +0200
1603 cblk->numpasses = (cblk->numbps > 0) ? (3 * cblk->numbps - 2) : 0;
1604 if (cblk->numpasses > 0) {
1605 - cblk->passes = jas_malloc(cblk->numpasses * sizeof(jpc_enc_pass_t));
1606 + cblk->passes = jas_malloc2(cblk->numpasses, sizeof(jpc_enc_pass_t));
1607 assert(cblk->passes);
1612 [FILE:497:patches/patch-jpc_t2cod.c]
1613 --- src/libjasper/jpc/jpc_t2cod.c.orig 2007-01-19 22:43:07.000000000 +0100
1614 +++ src/libjasper/jpc/jpc_t2cod.c 2013-04-17 22:32:23.000000000 +0200
1617 if (pchglist->numpchgs >= pchglist->maxpchgs) {
1618 newmaxpchgs = pchglist->maxpchgs + 128;
1619 - if (!(newpchgs = jas_realloc(pchglist->pchgs, newmaxpchgs * sizeof(jpc_pchg_t *)))) {
1620 + if (!(newpchgs = jas_realloc2(pchglist->pchgs, newmaxpchgs, sizeof(jpc_pchg_t *)))) {
1623 pchglist->maxpchgs = newmaxpchgs;
1626 [FILE:1122:patches/patch-jpc_t2dec.c]
1627 --- src/libjasper/jpc/jpc_t2dec.c.orig 2007-01-19 22:43:07.000000000 +0100
1628 +++ src/libjasper/jpc/jpc_t2dec.c 2013-04-17 22:32:23.000000000 +0200
1632 pi->numcomps = dec->numcomps;
1633 - if (!(pi->picomps = jas_malloc(pi->numcomps * sizeof(jpc_picomp_t)))) {
1634 + if (!(pi->picomps = jas_malloc2(pi->numcomps, sizeof(jpc_picomp_t)))) {
1639 for (compno = 0, tcomp = tile->tcomps, picomp = pi->picomps;
1640 compno < pi->numcomps; ++compno, ++tcomp, ++picomp) {
1641 picomp->numrlvls = tcomp->numrlvls;
1642 - if (!(picomp->pirlvls = jas_malloc(picomp->numrlvls *
1643 + if (!(picomp->pirlvls = jas_malloc2(picomp->numrlvls,
1644 sizeof(jpc_pirlvl_t)))) {
1648 rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) {
1649 /* XXX sizeof(long) should be sizeof different type */
1650 pirlvl->numprcs = rlvl->numprcs;
1651 - if (!(pirlvl->prclyrnos = jas_malloc(pirlvl->numprcs *
1652 + if (!(pirlvl->prclyrnos = jas_malloc2(pirlvl->numprcs,
1658 [FILE:1094:patches/patch-jpc_t2enc.c]
1659 --- src/libjasper/jpc/jpc_t2enc.c.orig 2007-01-19 22:43:07.000000000 +0100
1660 +++ src/libjasper/jpc/jpc_t2enc.c 2013-04-17 22:32:23.000000000 +0200
1664 pi->numcomps = cp->numcmpts;
1665 - if (!(pi->picomps = jas_malloc(pi->numcomps * sizeof(jpc_picomp_t)))) {
1666 + if (!(pi->picomps = jas_malloc2(pi->numcomps, sizeof(jpc_picomp_t)))) {
1671 for (compno = 0, tcomp = tile->tcmpts, picomp = pi->picomps;
1672 compno < pi->numcomps; ++compno, ++tcomp, ++picomp) {
1673 picomp->numrlvls = tcomp->numrlvls;
1674 - if (!(picomp->pirlvls = jas_malloc(picomp->numrlvls *
1675 + if (!(picomp->pirlvls = jas_malloc2(picomp->numrlvls,
1676 sizeof(jpc_pirlvl_t)))) {
1680 /* XXX sizeof(long) should be sizeof different type */
1681 pirlvl->numprcs = rlvl->numprcs;
1682 if (rlvl->numprcs) {
1683 - if (!(pirlvl->prclyrnos = jas_malloc(pirlvl->numprcs *
1684 + if (!(pirlvl->prclyrnos = jas_malloc2(pirlvl->numprcs,
1690 [FILE:389:patches/patch-jpc_tagtree.c]
1691 --- src/libjasper/jpc/jpc_tagtree.c.orig 2007-01-19 22:43:07.000000000 +0100
1692 +++ src/libjasper/jpc/jpc_tagtree.c 2013-04-17 22:32:23.000000000 +0200
1697 - if (!(tree->nodes_ = jas_malloc(tree->numnodes_ * sizeof(jpc_tagtreenode_t)))) {
1698 + if (!(tree->nodes_ = jas_malloc2(tree->numnodes_, sizeof(jpc_tagtreenode_t)))) {
1704 [FILE:300:patches/patch-jpc_util.c]
1705 --- src/libjasper/jpc/jpc_util.c.orig 2007-01-19 22:43:07.000000000 +0100
1706 +++ src/libjasper/jpc/jpc_util.c 2013-04-17 22:32:23.000000000 +0200
1711 - if (!(vs = jas_malloc(n * sizeof(double)))) {
1712 + if (!(vs = jas_malloc2(n, sizeof(double)))) {
1718 [FILE:290:patches/patch-libjasper-Makefile.in]
1719 --- src/libjasper/Makefile.in.orig Wed Feb 7 11:18:06 2007
1720 +++ src/libjasper/Makefile.in Wed Feb 7 11:18:28 2007
1723 # -release $(LT_RELEASE)
1724 libjasper_la_LDFLAGS = \
1725 - -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
1726 + -version-info 4:0:0
1732 [FILE:1394:patches/patch-mif_cod.c]
1733 --- src/libjasper/mif/mif_cod.c.orig 2007-01-19 22:43:05.000000000 +0100
1734 +++ src/libjasper/mif/mif_cod.c 2016-02-20 14:19:34.799575000 +0100
1736 static int mif_hdr_addcmpt(mif_hdr_t *hdr, int cmptno, mif_cmpt_t *cmpt);
1737 static mif_cmpt_t *mif_cmpt_create(void);
1738 static void mif_cmpt_destroy(mif_cmpt_t *cmpt);
1739 -static char *mif_getline(jas_stream_t *jas_stream, char *buf, int bufsize);
1740 +static char *mif_getline(jas_stream_t *jas_stream, char *buf, size_t bufsize);
1741 static int mif_getc(jas_stream_t *in);
1742 static mif_hdr_t *mif_makehdrfromimage(jas_image_t *image);
1746 mif_cmpt_t **newcmpts;
1747 assert(maxcmpts >= hdr->numcmpts);
1748 - newcmpts = (!hdr->cmpts) ? jas_malloc(maxcmpts * sizeof(mif_cmpt_t *)) :
1749 - jas_realloc(hdr->cmpts, maxcmpts * sizeof(mif_cmpt_t *));
1750 + newcmpts = jas_realloc2(hdr->cmpts, maxcmpts, sizeof(mif_cmpt_t *));
1757 jas_tvparser_destroy(tvp);
1758 + /* fix for CVE-2015-5221 */
1760 if (!cmpt->sampperx || !cmpt->samppery) {
1765 \******************************************************************************/
1767 -static char *mif_getline(jas_stream_t *stream, char *buf, int bufsize)
1768 +static char *mif_getline(jas_stream_t *stream, char *buf, size_t bufsize)
1774 [FILE:5495:patches/patch-uuid-support]
1776 # Jasper with uuid patch, required by GDAL, can be downloaded from:
1777 # - http://download.osgeo.org/gdal/
1778 # - http://www.gdal.org/dl/
1779 # - ftp://ftp.remotesensing.org/gdal/
1781 # Current version is jasper-1.900.1.uuid.tar.gz.
1783 diff -ruN src/libjasper/jp2/jp2_cod.c.orig src/libjasper/jp2/jp2_cod.c
1784 --- src/libjasper/jp2/jp2_cod.c.orig 2007-01-20 05:43:05.000000000 +0800
1785 +++ src/libjasper/jp2/jp2_cod.c 2007-03-06 21:49:58.000000000 +0800
1787 * All rights reserved.
1791 + * Modified by Andrey Kiselev <dron@ak4719.spb.edu> to properly handle UUID
1795 /* __START_OF_JASPER_LICENSE__
1797 * JasPer License Version 2.0
1799 static int jp2_pclr_getdata(jp2_box_t *box, jas_stream_t *in);
1800 static int jp2_pclr_putdata(jp2_box_t *box, jas_stream_t *out);
1801 static void jp2_pclr_dumpdata(jp2_box_t *box, FILE *out);
1802 +static void jp2_uuid_destroy(jp2_box_t *box);
1803 +static int jp2_uuid_getdata(jp2_box_t *box, jas_stream_t *in);
1804 +static int jp2_uuid_putdata(jp2_box_t *box, jas_stream_t *out);
1806 /******************************************************************************\
1809 {JP2_BOX_XML, "XML", 0,
1811 {JP2_BOX_UUID, "UUID", 0,
1813 + {0, jp2_uuid_destroy, jp2_uuid_getdata, jp2_uuid_putdata, 0}},
1814 {JP2_BOX_UINF, "UINF", JP2_BOX_SUPER,
1816 {JP2_BOX_ULST, "ULST", 0,
1819 box->datalen = box->len - JP2_BOX_HDRLEN(false);
1821 - if (box->len != 0 && box->len < 8) {
1822 + if (box->len != 0 && box->len < JP2_BOX_HDRLEN(false)) {
1826 @@ -876,6 +884,56 @@
1830 +static void jp2_uuid_destroy(jp2_box_t *box)
1832 + jp2_uuid_t *uuid = &box->data.uuid;
1835 + jas_free(uuid->data);
1836 + uuid->data = NULL;
1840 +static int jp2_uuid_getdata(jp2_box_t *box, jas_stream_t *in)
1842 + jp2_uuid_t *uuid = &box->data.uuid;
1845 + for (i = 0; i < 16; i++)
1847 + if (jp2_getuint8(in, &uuid->uuid[i]))
1851 + uuid->datalen = box->datalen - 16;
1852 + uuid->data = jas_malloc(uuid->datalen * sizeof(uint_fast8_t));
1853 + for (i = 0; i < uuid->datalen; i++)
1855 + if (jp2_getuint8(in, &uuid->data[i]))
1861 +static int jp2_uuid_putdata(jp2_box_t *box, jas_stream_t *out)
1863 + jp2_uuid_t *uuid = &box->data.uuid;
1866 + for (i = 0; i < 16; i++)
1868 + if (jp2_putuint8(out, uuid->uuid[i]))
1872 + for (i = 0; i < uuid->datalen; i++)
1874 + if (jp2_putuint8(out, uuid->data[i]))
1880 static int jp2_getint(jas_stream_t *in, int s, int n, int_fast32_t *val)
1883 diff -ruN src/libjasper/jp2/jp2_cod.h.orig src/libjasper/jp2/jp2_cod.h
1884 --- src/libjasper/jp2/jp2_cod.h.orig 2007-01-20 05:43:05.000000000 +0800
1885 +++ src/libjasper/jp2/jp2_cod.h 2007-03-06 21:49:58.000000000 +0800
1887 * All rights reserved.
1891 + * Modified by Andrey Kiselev <dron@ak4719.spb.edu> to properly handle UUID
1895 /* __START_OF_JASPER_LICENSE__
1897 * JasPer License Version 2.0
1898 @@ -229,6 +234,12 @@
1899 jp2_cmapent_t *ents;
1903 + uint_fast32_t datalen;
1904 + uint_fast8_t uuid[16];
1905 + uint_fast8_t *data;
1908 #define JP2_CMAP_DIRECT 0
1909 #define JP2_CMAP_PALETTE 1
1919 diff -ruN src/libjasper/jp2/jp2_enc.c.orig src/libjasper/jp2/jp2_enc.c
1920 --- src/libjasper/jp2/jp2_enc.c.orig 2007-01-20 05:43:05.000000000 +0800
1921 +++ src/libjasper/jp2/jp2_enc.c 2007-03-06 21:49:58.000000000 +0800
1923 * All rights reserved.
1927 + * Modified by Andrey Kiselev <dron@ak4719.spb.edu> to properly handle UUID
1931 /* __START_OF_JASPER_LICENSE__
1933 * JasPer License Version 2.0
1936 \******************************************************************************/
1938 -int jp2_encode(jas_image_t *image, jas_stream_t *out, char *optstr)
1939 +int jp2_write_header(jas_image_t *image, jas_stream_t *out)
1945 uint_fast16_t cmptno;
1948 - uint_fast32_t overhead;
1949 jp2_cdefchan_t *cdefchanent;
1952 @@ -326,6 +329,26 @@
1953 jas_stream_close(tmpstream);
1962 + jp2_box_destroy(box);
1965 + jas_stream_close(tmpstream);
1970 +int jp2_write_codestream(jas_image_t *image, jas_stream_t *out, char *optstr)
1974 + uint_fast32_t overhead;
1977 * Output the contiguous code stream box.
1979 @@ -358,12 +381,34 @@
1981 jp2_box_destroy(box);
1984 - jas_stream_close(tmpstream);
1989 +int jp2_encode(jas_image_t *image, jas_stream_t *out, char *optstr)
1991 + if (jp2_write_header(image, out) < 0)
1993 + if (jp2_write_codestream(image, out, optstr) < 0)
1999 +int jp2_encode_uuid(jas_image_t *image, jas_stream_t *out,
2000 + char *optstr, jp2_box_t *uuid)
2002 + if (jp2_write_header(image, out) < 0)
2005 + if (jp2_box_put(uuid, out))
2008 + if (jp2_write_codestream(image, out, optstr) < 0)
2014 static uint_fast32_t jp2_gettypeasoc(int colorspace, int ctype)