diff --git a/nativeLib/files.native/awipsShare/hydroapps/lib/native/linux32/libjasper.so.1.0.0 b/nativeLib/files.native/awipsShare/hydroapps/lib/native/linux32/libjasper.so.1.0.0 index 570902ae5d..6a490b270b 100755 Binary files a/nativeLib/files.native/awipsShare/hydroapps/lib/native/linux32/libjasper.so.1.0.0 and b/nativeLib/files.native/awipsShare/hydroapps/lib/native/linux32/libjasper.so.1.0.0 differ diff --git a/nativeLib/files.native/edex/lib/native/linux32/libjasper.so.1.0.0 b/nativeLib/files.native/edex/lib/native/linux32/libjasper.so.1.0.0 index 570902ae5d..6a490b270b 100755 Binary files a/nativeLib/files.native/edex/lib/native/linux32/libjasper.so.1.0.0 and b/nativeLib/files.native/edex/lib/native/linux32/libjasper.so.1.0.0 differ diff --git a/nativeLib/rary.cots.jasper/jasper-1.900.1-security_fixes-1.patch b/nativeLib/rary.cots.jasper/jasper-1.900.1-security_fixes-2.patch similarity index 67% rename from nativeLib/rary.cots.jasper/jasper-1.900.1-security_fixes-1.patch rename to nativeLib/rary.cots.jasper/jasper-1.900.1-security_fixes-2.patch index 469560c73c..298ff84df0 100644 --- a/nativeLib/rary.cots.jasper/jasper-1.900.1-security_fixes-1.patch +++ b/nativeLib/rary.cots.jasper/jasper-1.900.1-security_fixes-2.patch @@ -1,16 +1,17 @@ -Submitted By: Ken Moffat -Date: 2008-12-29 -Initial Package Version: 1.900.1, but has some offsets -Upstream Status: unknown -Origin: Debian. I suspect this originated at gentoo, but the links to their bzip2ed -patch were dead. -Description: Vulnerability fixes for CVE-2008-352{0..2} +Submitted By: Armin K. +Date: 2015-01-28 +Initial Package Version: 1.900.1 +Upstream Status: Unknown +Origin: Archlinux +Description: Fixes multiple security issues, including: + CVE-2008-3520, CVE-2008-3522, CVE-2011-4516, CVE-2011-4517, + CVE-2014-8137, CVE-2014-8138, CVE-2014-8157, CVE-2014-8158 and + CVE-2014-9029. Filename buffer overflow and Stepsizes overflow. +#This was updated to fix jpc_qmfb.c as it was updated as put of the 64 compatibility upgrade -diff --git a/src/libjasper/base/jas_cm.c b/src/libjasper/base/jas_cm.c -index 77514dd..e63a6d2 100644 ---- a/src/libjasper/base/jas_cm.c -+++ b/src/libjasper/base/jas_cm.c -@@ -704,8 +704,7 @@ static int jas_cmpxformseq_resize(jas_cmpxformseq_t *pxformseq, int n) +--- a/src/libjasper/base/jas_cm.c 2007-01-19 22:43:05.000000000 +0100 ++++ b/src/libjasper/base/jas_cm.c 2015-01-28 17:57:34.114045370 +0100 +@@ -704,8 +704,7 @@ { jas_cmpxform_t **p; assert(n >= pxformseq->numpxforms); @@ -20,7 +21,7 @@ index 77514dd..e63a6d2 100644 if (!p) { return -1; } -@@ -889,13 +888,13 @@ static int jas_cmshapmatlut_set(jas_cmshapmatlut_t *lut, jas_icccurv_t *curv) +@@ -889,13 +888,13 @@ jas_cmshapmatlut_cleanup(lut); if (curv->numents == 0) { lut->size = 2; @@ -36,7 +37,7 @@ index 77514dd..e63a6d2 100644 goto error; gamma = curv->ents[0] / 256.0; for (i = 0; i < lut->size; ++i) { -@@ -903,7 +902,7 @@ static int jas_cmshapmatlut_set(jas_cmshapmatlut_t *lut, jas_icccurv_t *curv) +@@ -903,7 +902,7 @@ } } else { lut->size = curv->numents; @@ -45,7 +46,7 @@ index 77514dd..e63a6d2 100644 goto error; for (i = 0; i < lut->size; ++i) { lut->data[i] = curv->ents[i] / 65535.0; -@@ -953,7 +952,7 @@ static int jas_cmshapmatlut_invert(jas_cmshapmatlut_t *invlut, +@@ -953,7 +952,7 @@ return -1; } } @@ -54,11 +55,9 @@ index 77514dd..e63a6d2 100644 return -1; invlut->size = n; for (i = 0; i < invlut->size; ++i) { -diff --git a/src/libjasper/base/jas_icc.c b/src/libjasper/base/jas_icc.c -index e5a0a2e..6fb2721 100644 ---- a/src/libjasper/base/jas_icc.c -+++ b/src/libjasper/base/jas_icc.c -@@ -373,7 +373,7 @@ int jas_iccprof_save(jas_iccprof_t *prof, jas_stream_t *out) +--- a/src/libjasper/base/jas_icc.c 2007-01-19 22:43:05.000000000 +0100 ++++ b/src/libjasper/base/jas_icc.c 2015-01-28 17:58:32.874025377 +0100 +@@ -373,7 +373,7 @@ jas_icctagtab_t *tagtab; tagtab = &prof->tagtab; @@ -67,7 +66,7 @@ index e5a0a2e..6fb2721 100644 sizeof(jas_icctagtabent_t)))) goto error; tagtab->numents = prof->attrtab->numattrs; -@@ -522,7 +522,7 @@ static int jas_iccprof_gettagtab(jas_stream_t *in, jas_icctagtab_t *tagtab) +@@ -522,7 +522,7 @@ } if (jas_iccgetuint32(in, &tagtab->numents)) goto error; @@ -76,7 +75,7 @@ index e5a0a2e..6fb2721 100644 sizeof(jas_icctagtabent_t)))) goto error; tagtabent = tagtab->ents; -@@ -743,8 +743,7 @@ static int jas_iccattrtab_resize(jas_iccattrtab_t *tab, int maxents) +@@ -743,8 +743,7 @@ { jas_iccattr_t *newattrs; assert(maxents >= tab->numattrs); @@ -86,7 +85,7 @@ index e5a0a2e..6fb2721 100644 if (!newattrs) return -1; tab->attrs = newattrs; -@@ -999,7 +998,7 @@ static int jas_icccurv_input(jas_iccattrval_t *attrval, jas_stream_t *in, +@@ -999,7 +998,7 @@ if (jas_iccgetuint32(in, &curv->numents)) goto error; @@ -95,7 +94,15 @@ index e5a0a2e..6fb2721 100644 goto error; for (i = 0; i < curv->numents; ++i) { if (jas_iccgetuint16(in, &curv->ents[i])) -@@ -1100,7 +1099,7 @@ static int jas_icctxtdesc_input(jas_iccattrval_t *attrval, jas_stream_t *in, +@@ -1011,7 +1010,6 @@ + return 0; + + error: +- jas_icccurv_destroy(attrval); + return -1; + } + +@@ -1100,7 +1098,7 @@ if (jas_iccgetuint32(in, &txtdesc->uclangcode) || jas_iccgetuint32(in, &txtdesc->uclen)) goto error; @@ -104,7 +111,24 @@ index e5a0a2e..6fb2721 100644 goto error; if (jas_stream_read(in, txtdesc->ucdata, txtdesc->uclen * 2) != JAS_CAST(int, txtdesc->uclen * 2)) -@@ -1292,17 +1291,17 @@ static int jas_icclut8_input(jas_iccattrval_t *attrval, jas_stream_t *in, +@@ -1129,7 +1127,6 @@ + #endif + return 0; + error: +- jas_icctxtdesc_destroy(attrval); + return -1; + } + +@@ -1208,8 +1205,6 @@ + goto error; + return 0; + error: +- if (txt->string) +- jas_free(txt->string); + return -1; + } + +@@ -1292,17 +1287,17 @@ jas_iccgetuint16(in, &lut8->numouttabents)) goto error; clutsize = jas_iccpowi(lut8->clutlen, lut8->numinchans) * lut8->numoutchans; @@ -129,7 +153,15 @@ index e5a0a2e..6fb2721 100644 sizeof(jas_iccuint8_t *)))) goto error; for (i = 0; i < lut8->numoutchans; ++i) -@@ -1461,17 +1460,17 @@ static int jas_icclut16_input(jas_iccattrval_t *attrval, jas_stream_t *in, +@@ -1330,7 +1325,6 @@ + goto error; + return 0; + error: +- jas_icclut8_destroy(attrval); + return -1; + } + +@@ -1461,17 +1455,17 @@ jas_iccgetuint16(in, &lut16->numouttabents)) goto error; clutsize = jas_iccpowi(lut16->clutlen, lut16->numinchans) * lut16->numoutchans; @@ -154,11 +186,17 @@ index e5a0a2e..6fb2721 100644 sizeof(jas_iccuint16_t *)))) goto error; for (i = 0; i < lut16->numoutchans; ++i) -diff --git a/src/libjasper/base/jas_image.c b/src/libjasper/base/jas_image.c -index 876debb..c09974b 100644 ---- a/src/libjasper/base/jas_image.c -+++ b/src/libjasper/base/jas_image.c -@@ -142,7 +142,7 @@ jas_image_t *jas_image_create(int numcmpts, jas_image_cmptparm_t *cmptparms, +@@ -1499,7 +1493,6 @@ + goto error; + return 0; + error: +- jas_icclut16_destroy(attrval); + return -1; + } + +--- a/src/libjasper/base/jas_image.c 2007-01-19 22:43:05.000000000 +0100 ++++ b/src/libjasper/base/jas_image.c 2015-01-28 17:57:34.116045403 +0100 +@@ -142,7 +142,7 @@ image->inmem_ = true; /* Allocate memory for the per-component information. */ @@ -167,7 +205,7 @@ index 876debb..c09974b 100644 sizeof(jas_image_cmpt_t *)))) { jas_image_destroy(image); return 0; -@@ -774,8 +774,7 @@ static int jas_image_growcmpts(jas_image_t *image, int maxcmpts) +@@ -774,8 +774,7 @@ jas_image_cmpt_t **newcmpts; int cmptno; @@ -177,10 +215,8 @@ index 876debb..c09974b 100644 if (!newcmpts) { return -1; } -diff --git a/src/libjasper/base/jas_malloc.c b/src/libjasper/base/jas_malloc.c -index 13f7bc8..90658e8 100644 ---- a/src/libjasper/base/jas_malloc.c -+++ b/src/libjasper/base/jas_malloc.c +--- a/src/libjasper/base/jas_malloc.c 2007-01-19 22:43:05.000000000 +0100 ++++ b/src/libjasper/base/jas_malloc.c 2015-01-28 17:57:34.116045403 +0100 @@ -76,6 +76,9 @@ /* We need the prototype for memset. */ @@ -191,7 +227,7 @@ index 13f7bc8..90658e8 100644 #include "jasper/jas_malloc.h" -@@ -113,18 +116,50 @@ void jas_free(void *ptr) +@@ -113,18 +116,50 @@ void *jas_realloc(void *ptr, size_t size) { @@ -249,11 +285,9 @@ index 13f7bc8..90658e8 100644 return ptr; } -diff --git a/src/libjasper/base/jas_seq.c b/src/libjasper/base/jas_seq.c -index 16e1778..672b60f 100644 ---- a/src/libjasper/base/jas_seq.c -+++ b/src/libjasper/base/jas_seq.c -@@ -114,7 +114,7 @@ jas_matrix_t *jas_matrix_create(int numrows, int numcols) +--- a/src/libjasper/base/jas_seq.c 2007-01-19 22:43:05.000000000 +0100 ++++ b/src/libjasper/base/jas_seq.c 2015-01-28 17:57:34.116045403 +0100 +@@ -114,7 +114,7 @@ matrix->datasize_ = numrows * numcols; if (matrix->maxrows_ > 0) { @@ -262,7 +296,7 @@ index 16e1778..672b60f 100644 sizeof(jas_seqent_t *)))) { jas_matrix_destroy(matrix); return 0; -@@ -122,7 +122,7 @@ jas_matrix_t *jas_matrix_create(int numrows, int numcols) +@@ -122,7 +122,7 @@ } if (matrix->datasize_ > 0) { @@ -271,7 +305,7 @@ index 16e1778..672b60f 100644 sizeof(jas_seqent_t)))) { jas_matrix_destroy(matrix); return 0; -@@ -220,7 +220,7 @@ void jas_matrix_bindsub(jas_matrix_t *mat0, jas_matrix_t *mat1, int r0, int c0, +@@ -220,7 +220,7 @@ mat0->numrows_ = r1 - r0 + 1; mat0->numcols_ = c1 - c0 + 1; mat0->maxrows_ = mat0->numrows_; @@ -280,11 +314,9 @@ index 16e1778..672b60f 100644 for (i = 0; i < mat0->numrows_; ++i) { mat0->rows_[i] = mat1->rows_[r0 + i] + c0; } -diff --git a/src/libjasper/base/jas_stream.c b/src/libjasper/base/jas_stream.c -index 9a88556..61fcc64 100644 ---- a/src/libjasper/base/jas_stream.c -+++ b/src/libjasper/base/jas_stream.c -@@ -212,7 +212,7 @@ jas_stream_t *jas_stream_memopen(char *buf, int bufsize) +--- a/src/libjasper/base/jas_stream.c 2007-01-19 22:43:05.000000000 +0100 ++++ b/src/libjasper/base/jas_stream.c 2015-01-28 17:57:57.483434550 +0100 +@@ -212,7 +212,7 @@ if (buf) { obj->buf_ = (unsigned char *) buf; } else { @@ -293,40 +325,7 @@ index 9a88556..61fcc64 100644 obj->myalloc_ = 1; } if (!obj->buf_) { -@@ -361,28 +361,22 @@ jas_stream_t *jas_stream_tmpfile() - } - obj->fd = -1; - obj->flags = 0; -- obj->pathname[0] = '\0'; - stream->obj_ = obj; - - /* Choose a file name. */ -- tmpnam(obj->pathname); -+ snprintf(obj->pathname, L_tmpnam, "%stmp.XXXXXXXXXX", P_tmpdir); - - /* Open the underlying file. */ -- if ((obj->fd = open(obj->pathname, O_CREAT | O_EXCL | O_RDWR | O_TRUNC | O_BINARY, -- JAS_STREAM_PERMS)) < 0) { -+ if ((obj->fd = mkstemp(obj->pathname)) < 0) { - jas_stream_destroy(stream); - return 0; - } - - /* Unlink the file so that it will disappear if the program - terminates abnormally. */ -- /* Under UNIX, one can unlink an open file and continue to do I/O -- on it. Not all operating systems support this functionality, however. -- For example, under Microsoft Windows the unlink operation will fail, -- since the file is open. */ - if (unlink(obj->pathname)) { -- /* We will try unlinking the file again after it is closed. */ -- obj->flags |= JAS_STREAM_FILEOBJ_DELONCLOSE; -+ jas_stream_destroy(stream); -+ return 0; - } - - /* Use full buffering. */ -@@ -553,7 +547,7 @@ int jas_stream_printf(jas_stream_t *stream, const char *fmt, ...) +@@ -553,7 +553,7 @@ int ret; va_start(ap, fmt); @@ -335,7 +334,7 @@ index 9a88556..61fcc64 100644 jas_stream_puts(stream, buf); va_end(ap); return ret; -@@ -992,7 +986,7 @@ static int mem_resize(jas_stream_memobj_t *m, int bufsize) +@@ -992,7 +992,7 @@ unsigned char *buf; assert(m->buf_); @@ -344,11 +343,9 @@ index 9a88556..61fcc64 100644 return -1; } m->buf_ = buf; -diff --git a/src/libjasper/bmp/bmp_dec.c b/src/libjasper/bmp/bmp_dec.c -index 4cb0df3..7a6dcb1 100644 ---- a/src/libjasper/bmp/bmp_dec.c -+++ b/src/libjasper/bmp/bmp_dec.c -@@ -283,7 +283,7 @@ static bmp_info_t *bmp_getinfo(jas_stream_t *in) +--- a/src/libjasper/bmp/bmp_dec.c 2007-01-19 22:43:07.000000000 +0100 ++++ b/src/libjasper/bmp/bmp_dec.c 2015-01-28 17:57:34.117045420 +0100 +@@ -283,7 +283,7 @@ } if (info->numcolors > 0) { @@ -357,11 +354,9 @@ index 4cb0df3..7a6dcb1 100644 sizeof(bmp_palent_t)))) { bmp_info_destroy(info); return 0; -diff --git a/src/libjasper/include/jasper/jas_malloc.h b/src/libjasper/include/jasper/jas_malloc.h -index f2a8f8b..258e4c7 100644 ---- a/src/libjasper/include/jasper/jas_malloc.h -+++ b/src/libjasper/include/jasper/jas_malloc.h -@@ -95,6 +95,9 @@ extern "C" { +--- a/src/libjasper/include/jasper/jas_malloc.h 2007-01-19 22:43:04.000000000 +0100 ++++ b/src/libjasper/include/jasper/jas_malloc.h 2015-01-28 17:57:34.118045437 +0100 +@@ -95,6 +95,9 @@ #define jas_free MEMFREE #define jas_realloc MEMREALLOC #define jas_calloc MEMCALLOC @@ -371,7 +366,7 @@ index f2a8f8b..258e4c7 100644 #endif /******************************************************************************\ -@@ -115,6 +118,12 @@ void *jas_realloc(void *ptr, size_t size); +@@ -115,6 +118,12 @@ /* Allocate a block of memory and initialize the contents to zero. */ void *jas_calloc(size_t nmemb, size_t size); @@ -384,11 +379,18 @@ index f2a8f8b..258e4c7 100644 #endif #ifdef __cplusplus -diff --git a/src/libjasper/jp2/jp2_cod.c b/src/libjasper/jp2/jp2_cod.c -index d0bf058..8edf453 100644 ---- a/src/libjasper/jp2/jp2_cod.c -+++ b/src/libjasper/jp2/jp2_cod.c -@@ -380,7 +380,7 @@ static int jp2_bpcc_getdata(jp2_box_t *box, jas_stream_t *in) +--- a/src/libjasper/jp2/jp2_cod.c 2007-01-19 22:43:05.000000000 +0100 ++++ b/src/libjasper/jp2/jp2_cod.c 2015-01-28 17:57:34.118045437 +0100 +@@ -247,7 +247,7 @@ + box = 0; + tmpstream = 0; + +- if (!(box = jas_malloc(sizeof(jp2_box_t)))) { ++ if (!(box = jas_calloc(1, sizeof(jp2_box_t)))) { + goto error; + } + box->ops = &jp2_boxinfo_unk.ops; +@@ -372,7 +372,7 @@ jp2_bpcc_t *bpcc = &box->data.bpcc; unsigned int i; bpcc->numcmpts = box->datalen; @@ -397,7 +399,7 @@ index d0bf058..8edf453 100644 return -1; } for (i = 0; i < bpcc->numcmpts; ++i) { -@@ -424,7 +424,7 @@ static int jp2_colr_getdata(jp2_box_t *box, jas_stream_t *in) +@@ -416,7 +416,7 @@ break; case JP2_COLR_ICC: colr->iccplen = box->datalen - 3; @@ -406,7 +408,7 @@ index d0bf058..8edf453 100644 return -1; } if (jas_stream_read(in, colr->iccp, colr->iccplen) != colr->iccplen) { -@@ -461,7 +461,7 @@ static int jp2_cdef_getdata(jp2_box_t *box, jas_stream_t *in) +@@ -453,7 +453,7 @@ if (jp2_getuint16(in, &cdef->numchans)) { return -1; } @@ -415,7 +417,7 @@ index d0bf058..8edf453 100644 return -1; } for (channo = 0; channo < cdef->numchans; ++channo) { -@@ -774,7 +774,7 @@ static int jp2_cmap_getdata(jp2_box_t *box, jas_stream_t *in) +@@ -766,7 +766,7 @@ unsigned int i; cmap->numchans = (box->datalen) / 4; @@ -424,7 +426,7 @@ index d0bf058..8edf453 100644 return -1; } for (i = 0; i < cmap->numchans; ++i) { -@@ -836,10 +836,10 @@ static int jp2_pclr_getdata(jp2_box_t *box, jas_stream_t *in) +@@ -828,10 +828,10 @@ return -1; } lutsize = pclr->numlutents * pclr->numchans; @@ -437,11 +439,21 @@ index d0bf058..8edf453 100644 return -1; } for (i = 0; i < pclr->numchans; ++i) { -diff --git a/src/libjasper/jp2/jp2_dec.c b/src/libjasper/jp2/jp2_dec.c -index 65772de..5f7be7e 100644 ---- a/src/libjasper/jp2/jp2_dec.c -+++ b/src/libjasper/jp2/jp2_dec.c -@@ -336,7 +336,7 @@ jas_image_t *jp2_decode(jas_stream_t *in, char *optstr) +--- a/src/libjasper/jp2/jp2_dec.c 2007-01-19 22:43:05.000000000 +0100 ++++ b/src/libjasper/jp2/jp2_dec.c 2015-01-28 18:01:07.082617636 +0100 +@@ -291,7 +291,10 @@ + case JP2_COLR_ICC: + iccprof = jas_iccprof_createfrombuf(dec->colr->data.colr.iccp, + dec->colr->data.colr.iccplen); +- assert(iccprof); ++ if (!iccprof) { ++ jas_eprintf("error: failed to parse ICC profile\n"); ++ goto error; ++ } + jas_iccprof_gethdr(iccprof, &icchdr); + jas_eprintf("ICC Profile CS %08x\n", icchdr.colorspc); + jas_image_setclrspc(dec->image, fromiccpcs(icchdr.colorspc)); +@@ -336,7 +339,7 @@ } /* Allocate space for the channel-number to component-number LUT. */ @@ -450,7 +462,7 @@ index 65772de..5f7be7e 100644 jas_eprintf("error: no memory\n"); goto error; } -@@ -354,7 +354,7 @@ jas_image_t *jp2_decode(jas_stream_t *in, char *optstr) +@@ -354,7 +357,7 @@ if (cmapent->map == JP2_CMAP_DIRECT) { dec->chantocmptlut[channo] = channo; } else if (cmapent->map == JP2_CMAP_PALETTE) { @@ -459,11 +471,21 @@ index 65772de..5f7be7e 100644 for (i = 0; i < pclrd->numlutents; ++i) { lutents[i] = pclrd->lutdata[cmapent->pcol + i * pclrd->numchans]; } -diff --git a/src/libjasper/jp2/jp2_enc.c b/src/libjasper/jp2/jp2_enc.c -index d41392f..b837612 100644 ---- a/src/libjasper/jp2/jp2_enc.c -+++ b/src/libjasper/jp2/jp2_enc.c -@@ -194,7 +194,7 @@ int sgnd; +@@ -386,6 +389,11 @@ + /* Determine the type of each component. */ + if (dec->cdef) { + for (i = 0; i < dec->numchans; ++i) { ++ /* Is the channel number reasonable? */ ++ if (dec->cdef->data.cdef.ents[i].channo >= dec->numchans) { ++ jas_eprintf("error: invalid channel number in CDEF box\n"); ++ goto error; ++ } + jas_image_setcmpttype(dec->image, + dec->chantocmptlut[dec->cdef->data.cdef.ents[i].channo], + jp2_getct(jas_image_clrspc(dec->image), +--- a/src/libjasper/jp2/jp2_enc.c 2007-01-19 22:43:05.000000000 +0100 ++++ b/src/libjasper/jp2/jp2_enc.c 2015-01-28 17:57:34.119045453 +0100 +@@ -191,7 +191,7 @@ } bpcc = &box->data.bpcc; bpcc->numcmpts = jas_image_numcmpts(image); @@ -472,7 +494,7 @@ index d41392f..b837612 100644 sizeof(uint_fast8_t)))) { goto error; } -@@ -288,7 +288,7 @@ int sgnd; +@@ -285,7 +285,7 @@ } cdef = &box->data.cdef; cdef->numchans = jas_image_numcmpts(image); @@ -481,11 +503,9 @@ index d41392f..b837612 100644 for (i = 0; i < jas_image_numcmpts(image); ++i) { cdefchanent = &cdef->ents[i]; cdefchanent->channo = i; -diff --git a/src/libjasper/jpc/jpc_cs.c b/src/libjasper/jpc/jpc_cs.c -index f076571..d1fe721 100644 ---- a/src/libjasper/jpc/jpc_cs.c -+++ b/src/libjasper/jpc/jpc_cs.c -@@ -502,7 +502,7 @@ static int jpc_siz_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, +--- a/src/libjasper/jpc/jpc_cs.c 2007-01-19 22:43:07.000000000 +0100 ++++ b/src/libjasper/jpc/jpc_cs.c 2015-01-28 17:57:34.120045470 +0100 +@@ -502,7 +502,7 @@ !siz->tileheight || !siz->numcomps) { return -1; } @@ -494,7 +514,21 @@ index f076571..d1fe721 100644 return -1; } for (i = 0; i < siz->numcomps; ++i) { -@@ -1091,7 +1091,7 @@ static int jpc_ppm_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in +@@ -982,8 +982,11 @@ + compparms->numstepsizes = (len - n) / 2; + break; + } +- if (compparms->numstepsizes > 0) { +- compparms->stepsizes = jas_malloc(compparms->numstepsizes * ++ if (compparms->numstepsizes > 3 * JPC_MAXRLVLS + 1) { ++ jpc_qcx_destroycompparms(compparms); ++ return -1; ++ } else if (compparms->numstepsizes > 0) { ++ compparms->stepsizes = jas_alloc2(compparms->numstepsizes, + sizeof(uint_fast16_t)); + assert(compparms->stepsizes); + for (i = 0; i < compparms->numstepsizes; ++i) { +@@ -1091,7 +1094,7 @@ ppm->len = ms->len - 1; if (ppm->len > 0) { @@ -503,7 +537,7 @@ index f076571..d1fe721 100644 goto error; } if (JAS_CAST(uint, jas_stream_read(in, ppm->data, ppm->len)) != ppm->len) { -@@ -1160,7 +1160,7 @@ static int jpc_ppt_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in +@@ -1160,7 +1163,7 @@ } ppt->len = ms->len - 1; if (ppt->len > 0) { @@ -512,7 +546,7 @@ index f076571..d1fe721 100644 goto error; } if (jas_stream_read(in, (char *) ppt->data, ppt->len) != JAS_CAST(int, ppt->len)) { -@@ -1223,7 +1223,7 @@ static int jpc_poc_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in +@@ -1223,7 +1226,7 @@ uint_fast8_t tmp; poc->numpchgs = (cstate->numcomps > 256) ? (ms->len / 9) : (ms->len / 7); @@ -521,7 +555,7 @@ index f076571..d1fe721 100644 goto error; } for (pchgno = 0, pchg = poc->pchgs; pchgno < poc->numpchgs; ++pchgno, -@@ -1328,7 +1328,7 @@ static int jpc_crg_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in +@@ -1328,7 +1331,7 @@ jpc_crgcomp_t *comp; uint_fast16_t compno; crg->numcomps = cstate->numcomps; @@ -530,7 +564,7 @@ index f076571..d1fe721 100644 return -1; } for (compno = 0, comp = crg->comps; compno < cstate->numcomps; -@@ -1467,7 +1467,7 @@ static int jpc_unk_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in +@@ -1467,7 +1470,7 @@ cstate = 0; if (ms->len > 0) { @@ -539,11 +573,9 @@ index f076571..d1fe721 100644 return -1; } if (jas_stream_read(in, (char *) unk->data, ms->len) != JAS_CAST(int, ms->len)) { -diff --git a/src/libjasper/jpc/jpc_dec.c b/src/libjasper/jpc/jpc_dec.c -index fa72a0e..b1ea056 100644 ---- a/src/libjasper/jpc/jpc_dec.c -+++ b/src/libjasper/jpc/jpc_dec.c -@@ -449,7 +449,7 @@ static int jpc_dec_process_sot(jpc_dec_t *dec, jpc_ms_t *ms) +--- a/src/libjasper/jpc/jpc_dec.c 2007-01-19 22:43:07.000000000 +0100 ++++ b/src/libjasper/jpc/jpc_dec.c 2015-01-28 17:59:44.748230228 +0100 +@@ -449,7 +449,7 @@ if (dec->state == JPC_MH) { @@ -552,7 +584,16 @@ index fa72a0e..b1ea056 100644 assert(compinfos); for (cmptno = 0, cmpt = dec->cmpts, compinfo = compinfos; cmptno < dec->numcomps; ++cmptno, ++cmpt, ++compinfo) { -@@ -692,7 +692,7 @@ static int jpc_dec_tileinit(jpc_dec_t *dec, jpc_dec_tile_t *tile) +@@ -489,7 +489,7 @@ + dec->curtileendoff = 0; + } + +- if (JAS_CAST(int, sot->tileno) > dec->numtiles) { ++ if (JAS_CAST(int, sot->tileno) >= dec->numtiles) { + jas_eprintf("invalid tile number in SOT marker segment\n"); + return -1; + } +@@ -692,7 +692,7 @@ tile->realmode = 1; } tcomp->numrlvls = ccp->numrlvls; @@ -561,7 +602,7 @@ index fa72a0e..b1ea056 100644 sizeof(jpc_dec_rlvl_t)))) { return -1; } -@@ -764,7 +764,7 @@ rlvl->bands = 0; +@@ -764,7 +764,7 @@ rlvl->cbgheightexpn); rlvl->numbands = (!rlvlno) ? 1 : 3; @@ -570,7 +611,7 @@ index fa72a0e..b1ea056 100644 sizeof(jpc_dec_band_t)))) { return -1; } -@@ -797,7 +797,7 @@ rlvl->bands = 0; +@@ -797,7 +797,7 @@ assert(rlvl->numprcs); @@ -579,7 +620,7 @@ index fa72a0e..b1ea056 100644 return -1; } -@@ -834,7 +834,7 @@ rlvl->bands = 0; +@@ -834,7 +834,7 @@ if (!(prc->numimsbstagtree = jpc_tagtree_create(prc->numhcblks, prc->numvcblks))) { return -1; } @@ -588,7 +629,22 @@ index fa72a0e..b1ea056 100644 return -1; } -@@ -1181,7 +1181,7 @@ static int jpc_dec_process_siz(jpc_dec_t *dec, jpc_ms_t *ms) +@@ -1069,12 +1069,12 @@ + /* Apply an inverse intercomponent transform if necessary. */ + switch (tile->cp->mctid) { + case JPC_MCT_RCT: +- assert(dec->numcomps == 3); ++ assert(dec->numcomps >= 3); + jpc_irct(tile->tcomps[0].data, tile->tcomps[1].data, + tile->tcomps[2].data); + break; + case JPC_MCT_ICT: +- assert(dec->numcomps == 3); ++ assert(dec->numcomps >= 3); + jpc_iict(tile->tcomps[0].data, tile->tcomps[1].data, + tile->tcomps[2].data); + break; +@@ -1181,7 +1181,7 @@ return -1; } @@ -597,25 +653,52 @@ index fa72a0e..b1ea056 100644 return -1; } -@@ -1204,7 +1204,7 @@ static int jpc_dec_process_siz(jpc_dec_t *dec, jpc_ms_t *ms) +@@ -1204,7 +1204,7 @@ dec->numhtiles = JPC_CEILDIV(dec->xend - dec->tilexoff, dec->tilewidth); dec->numvtiles = JPC_CEILDIV(dec->yend - dec->tileyoff, dec->tileheight); dec->numtiles = dec->numhtiles * dec->numvtiles; - if (!(dec->tiles = jas_malloc(dec->numtiles * sizeof(jpc_dec_tile_t)))) { -+ if (!(dec->tiles = jas_alloc2(dec->numtiles, sizeof(jpc_dec_tile_t)))) { ++ if (!(dec->tiles = jas_calloc(dec->numtiles, sizeof(jpc_dec_tile_t)))) { return -1; } -@@ -1228,7 +1228,7 @@ static int jpc_dec_process_siz(jpc_dec_t *dec, jpc_ms_t *ms) +@@ -1228,7 +1228,7 @@ tile->pkthdrstreampos = 0; tile->pptstab = 0; tile->cp = 0; - if (!(tile->tcomps = jas_malloc(dec->numcomps * -+ if (!(tile->tcomps = jas_alloc2(dec->numcomps, ++ if (!(tile->tcomps = jas_calloc(dec->numcomps, sizeof(jpc_dec_tcomp_t)))) { return -1; } -@@ -1489,7 +1489,7 @@ static jpc_dec_cp_t *jpc_dec_cp_create(uint_fast16_t numcomps) +@@ -1280,7 +1280,7 @@ + jpc_coc_t *coc = &ms->parms.coc; + jpc_dec_tile_t *tile; + +- if (JAS_CAST(int, coc->compno) > dec->numcomps) { ++ if (JAS_CAST(int, coc->compno) >= dec->numcomps) { + jas_eprintf("invalid component number in COC marker segment\n"); + return -1; + } +@@ -1306,7 +1306,7 @@ + jpc_rgn_t *rgn = &ms->parms.rgn; + jpc_dec_tile_t *tile; + +- if (JAS_CAST(int, rgn->compno) > dec->numcomps) { ++ if (JAS_CAST(int, rgn->compno) >= dec->numcomps) { + jas_eprintf("invalid component number in RGN marker segment\n"); + return -1; + } +@@ -1355,7 +1355,7 @@ + jpc_qcc_t *qcc = &ms->parms.qcc; + jpc_dec_tile_t *tile; + +- if (JAS_CAST(int, qcc->compno) > dec->numcomps) { ++ if (JAS_CAST(int, qcc->compno) >= dec->numcomps) { + jas_eprintf("invalid component number in QCC marker segment\n"); + return -1; + } +@@ -1489,7 +1489,7 @@ cp->numlyrs = 0; cp->mctid = 0; cp->csty = 0; @@ -624,7 +707,7 @@ index fa72a0e..b1ea056 100644 return 0; } if (!(cp->pchglist = jpc_pchglist_create())) { -@@ -2048,7 +2048,7 @@ jpc_streamlist_t *jpc_streamlist_create() +@@ -2048,7 +2048,7 @@ } streamlist->numstreams = 0; streamlist->maxstreams = 100; @@ -633,7 +716,7 @@ index fa72a0e..b1ea056 100644 sizeof(jas_stream_t *)))) { jas_free(streamlist); return 0; -@@ -2068,8 +2068,8 @@ int jpc_streamlist_insert(jpc_streamlist_t *streamlist, int streamno, +@@ -2068,8 +2068,8 @@ /* Grow the array of streams if necessary. */ if (streamlist->numstreams >= streamlist->maxstreams) { newmaxstreams = streamlist->maxstreams + 1024; @@ -644,7 +727,7 @@ index fa72a0e..b1ea056 100644 return -1; } for (i = streamlist->numstreams; i < streamlist->maxstreams; ++i) { -@@ -2155,8 +2155,7 @@ int jpc_ppxstab_grow(jpc_ppxstab_t *tab, int maxents) +@@ -2155,8 +2155,7 @@ { jpc_ppxstabent_t **newents; if (tab->maxents < maxents) { @@ -654,11 +737,9 @@ index fa72a0e..b1ea056 100644 if (!newents) { return -1; } -diff --git a/src/libjasper/jpc/jpc_enc.c b/src/libjasper/jpc/jpc_enc.c -index bbe1ef2..6299ead 100644 ---- a/src/libjasper/jpc/jpc_enc.c -+++ b/src/libjasper/jpc/jpc_enc.c -@@ -403,7 +403,7 @@ static jpc_enc_cp_t *cp_create(char *optstr, jas_image_t *image) +--- a/src/libjasper/jpc/jpc_enc.c 2007-01-19 22:43:07.000000000 +0100 ++++ b/src/libjasper/jpc/jpc_enc.c 2015-01-28 17:57:34.122045503 +0100 +@@ -403,7 +403,7 @@ vsteplcm *= jas_image_cmptvstep(image, cmptno); } @@ -667,7 +748,7 @@ index bbe1ef2..6299ead 100644 goto error; } for (cmptno = 0, ccp = cp->ccps; cmptno < JAS_CAST(int, cp->numcmpts); ++cmptno, -@@ -656,7 +656,7 @@ static jpc_enc_cp_t *cp_create(char *optstr, jas_image_t *image) +@@ -656,7 +656,7 @@ if (ilyrrates && numilyrrates > 0) { tcp->numlyrs = numilyrrates + 1; @@ -676,7 +757,7 @@ index bbe1ef2..6299ead 100644 sizeof(jpc_fix_t)))) { goto error; } -@@ -940,7 +940,7 @@ startoff = jas_stream_getrwcount(enc->out); +@@ -940,7 +940,7 @@ siz->tilewidth = cp->tilewidth; siz->tileheight = cp->tileheight; siz->numcomps = cp->numcmpts; @@ -685,7 +766,7 @@ index bbe1ef2..6299ead 100644 assert(siz->comps); for (i = 0; i < JAS_CAST(int, cp->numcmpts); ++i) { siz->comps[i].prec = cp->ccps[i].prec; -@@ -977,7 +977,7 @@ startoff = jas_stream_getrwcount(enc->out); +@@ -977,7 +977,7 @@ return -1; } crg = &enc->mrk->parms.crg; @@ -694,7 +775,7 @@ index bbe1ef2..6299ead 100644 if (jpc_putms(enc->out, enc->cstate, enc->mrk)) { jas_eprintf("cannot write CRG marker\n"); return -1; -@@ -1955,7 +1955,7 @@ jpc_enc_tile_t *jpc_enc_tile_create(jpc_enc_cp_t *cp, jas_image_t *image, int ti +@@ -1955,7 +1955,7 @@ tile->mctid = cp->tcp.mctid; tile->numlyrs = cp->tcp.numlyrs; @@ -703,7 +784,7 @@ index bbe1ef2..6299ead 100644 sizeof(uint_fast32_t)))) { goto error; } -@@ -1964,7 +1964,7 @@ jpc_enc_tile_t *jpc_enc_tile_create(jpc_enc_cp_t *cp, jas_image_t *image, int ti +@@ -1964,7 +1964,7 @@ } /* Allocate an array for the per-tile-component information. */ @@ -712,7 +793,7 @@ index bbe1ef2..6299ead 100644 goto error; } /* Initialize a few members critical for error recovery. */ -@@ -2110,7 +2110,7 @@ static jpc_enc_tcmpt_t *tcmpt_create(jpc_enc_tcmpt_t *tcmpt, jpc_enc_cp_t *cp, +@@ -2110,7 +2110,7 @@ jas_seq2d_ystart(tcmpt->data), jas_seq2d_xend(tcmpt->data), jas_seq2d_yend(tcmpt->data), bandinfos); @@ -721,7 +802,7 @@ index bbe1ef2..6299ead 100644 goto error; } for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls; -@@ -2213,7 +2213,7 @@ static jpc_enc_rlvl_t *rlvl_create(jpc_enc_rlvl_t *rlvl, jpc_enc_cp_t *cp, +@@ -2213,7 +2213,7 @@ rlvl->numvprcs = JPC_FLOORDIVPOW2(brprcbry - tlprctly, rlvl->prcheightexpn); rlvl->numprcs = rlvl->numhprcs * rlvl->numvprcs; @@ -730,7 +811,7 @@ index bbe1ef2..6299ead 100644 goto error; } for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; -@@ -2290,7 +2290,7 @@ if (bandinfo->xstart != bandinfo->xend && bandinfo->ystart != bandinfo->yend) { +@@ -2290,7 +2290,7 @@ band->synweight = bandinfo->synenergywt; if (band->data) { @@ -739,7 +820,7 @@ index bbe1ef2..6299ead 100644 goto error; } for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs; ++prcno, -@@ -2422,7 +2422,7 @@ if (!rlvlno) { +@@ -2422,7 +2422,7 @@ goto error; } @@ -748,11 +829,9 @@ index bbe1ef2..6299ead 100644 goto error; } for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks; -diff --git a/src/libjasper/jpc/jpc_mqdec.c b/src/libjasper/jpc/jpc_mqdec.c -index 4cc2f46..66a8581 100644 ---- a/src/libjasper/jpc/jpc_mqdec.c -+++ b/src/libjasper/jpc/jpc_mqdec.c -@@ -118,7 +118,7 @@ jpc_mqdec_t *jpc_mqdec_create(int maxctxs, jas_stream_t *in) +--- a/src/libjasper/jpc/jpc_mqdec.c 2007-01-19 22:43:07.000000000 +0100 ++++ b/src/libjasper/jpc/jpc_mqdec.c 2015-01-28 17:57:34.126045570 +0100 +@@ -118,7 +118,7 @@ mqdec->in = in; mqdec->maxctxs = maxctxs; /* Allocate memory for the per-context state information. */ @@ -761,11 +840,9 @@ index 4cc2f46..66a8581 100644 goto error; } /* Set the current context to the first context. */ -diff --git a/src/libjasper/jpc/jpc_mqenc.c b/src/libjasper/jpc/jpc_mqenc.c -index 758b361..399581e 100644 ---- a/src/libjasper/jpc/jpc_mqenc.c -+++ b/src/libjasper/jpc/jpc_mqenc.c -@@ -197,7 +197,7 @@ jpc_mqenc_t *jpc_mqenc_create(int maxctxs, jas_stream_t *out) +--- a/src/libjasper/jpc/jpc_mqenc.c 2007-01-19 22:43:07.000000000 +0100 ++++ b/src/libjasper/jpc/jpc_mqenc.c 2015-01-28 17:57:34.126045570 +0100 +@@ -197,7 +197,7 @@ mqenc->maxctxs = maxctxs; /* Allocate memory for the per-context state information. */ @@ -773,13 +850,11 @@ index 758b361..399581e 100644 + if (!(mqenc->ctxs = jas_alloc2(mqenc->maxctxs, sizeof(jpc_mqstate_t *)))) { goto error; } - -diff --git a/src/libjasper/jpc/jpc_qmfb.c b/src/libjasper/jpc/jpc_qmfb.c -index 00d406d..cf3320b 100644 ---- a/src/libjasper/jpc/jpc_qmfb.c -+++ b/src/libjasper/jpc/jpc_qmfb.c -@@ -321,7 +321,7 @@ void jpc_qmfb_split_row(jpc_fix_t *a, int numcols, int parity) - #if !defined(HAVE_VLA) + +# This was modified as the 64 bit conversion already removed the #define/#if +--- a/src/libjasper/jpc/jpc_qmfb.c 2007-01-19 22:43:07.000000000 +0100 ++++ b/src/libjasper/jpc/jpc_qmfb.c 2015-01-28 18:00:17.753785538 +0100 +@@ -324,6 +324,6 @@ /* Get a buffer. */ if (bufsize > QMFB_SPLITBUFSIZE) { - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { @@ -787,8 +862,7 @@ index 00d406d..cf3320b 100644 /* We have no choice but to commit suicide in this case. */ abort(); } -@@ -389,7 +389,7 @@ void jpc_qmfb_split_col(jpc_fix_t *a, int numrows, int stride, - #if !defined(HAVE_VLA) +@@ -384,6 +384,6 @@ /* Get a buffer. */ if (bufsize > QMFB_SPLITBUFSIZE) { - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { @@ -796,8 +870,7 @@ index 00d406d..cf3320b 100644 /* We have no choice but to commit suicide in this case. */ abort(); } -@@ -460,7 +460,7 @@ void jpc_qmfb_split_colgrp(jpc_fix_t *a, int numrows, int stride, - #if !defined(HAVE_VLA) +@@ -447,6 +447,6 @@ /* Get a buffer. */ if (bufsize > QMFB_SPLITBUFSIZE) { - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { @@ -805,8 +878,7 @@ index 00d406d..cf3320b 100644 /* We have no choice but to commit suicide in this case. */ abort(); } -@@ -549,7 +549,7 @@ void jpc_qmfb_split_colres(jpc_fix_t *a, int numrows, int numcols, - #if !defined(HAVE_VLA) +@@ -527,6 +527,6 @@ /* Get a buffer. */ if (bufsize > QMFB_SPLITBUFSIZE) { - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { @@ -814,8 +886,7 @@ index 00d406d..cf3320b 100644 /* We have no choice but to commit suicide in this case. */ abort(); } -@@ -633,7 +633,7 @@ void jpc_qmfb_join_row(jpc_fix_t *a, int numcols, int parity) - #if !defined(HAVE_VLA) +@@ -603,6 +603,6 @@ /* Allocate memory for the join buffer from the heap. */ if (bufsize > QMFB_JOINBUFSIZE) { - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { @@ -823,8 +894,7 @@ index 00d406d..cf3320b 100644 /* We have no choice but to commit suicide. */ abort(); } -@@ -698,7 +698,7 @@ void jpc_qmfb_join_col(jpc_fix_t *a, int numrows, int stride, - #if !defined(HAVE_VLA) +@@ -661,6 +661,6 @@ /* Allocate memory for the join buffer from the heap. */ if (bufsize > QMFB_JOINBUFSIZE) { - if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) { @@ -832,8 +902,7 @@ index 00d406d..cf3320b 100644 /* We have no choice but to commit suicide. */ abort(); } -@@ -766,7 +766,7 @@ void jpc_qmfb_join_colgrp(jpc_fix_t *a, int numrows, int stride, - #if !defined(HAVE_VLA) +@@ -722,6 +722,6 @@ /* Allocate memory for the join buffer from the heap. */ if (bufsize > QMFB_JOINBUFSIZE) { - if (!(buf = jas_malloc(bufsize * JPC_QMFB_COLGRPSIZE * sizeof(jpc_fix_t)))) { @@ -841,8 +910,7 @@ index 00d406d..cf3320b 100644 /* We have no choice but to commit suicide. */ abort(); } -@@ -852,7 +852,7 @@ void jpc_qmfb_join_colres(jpc_fix_t *a, int numrows, int numcols, - #if !defined(HAVE_VLA) +@@ -800,6 +800,6 @@ /* Allocate memory for the join buffer from the heap. */ if (bufsize > QMFB_JOINBUFSIZE) { - if (!(buf = jas_malloc(bufsize * numcols * sizeof(jpc_fix_t)))) { @@ -850,11 +918,9 @@ index 00d406d..cf3320b 100644 /* We have no choice but to commit suicide. */ abort(); } -diff --git a/src/libjasper/jpc/jpc_t1enc.c b/src/libjasper/jpc/jpc_t1enc.c -index 3a5acea..c8bfd21 100644 ---- a/src/libjasper/jpc/jpc_t1enc.c -+++ b/src/libjasper/jpc/jpc_t1enc.c -@@ -219,7 +219,7 @@ int jpc_enc_enccblk(jpc_enc_t *enc, jas_stream_t *out, jpc_enc_tcmpt_t *tcmpt, j +--- a/src/libjasper/jpc/jpc_t1enc.c 2007-01-19 22:43:07.000000000 +0100 ++++ b/src/libjasper/jpc/jpc_t1enc.c 2015-01-28 17:57:34.128045603 +0100 +@@ -219,7 +219,7 @@ cblk->numpasses = (cblk->numbps > 0) ? (3 * cblk->numbps - 2) : 0; if (cblk->numpasses > 0) { @@ -863,11 +929,9 @@ index 3a5acea..c8bfd21 100644 assert(cblk->passes); } else { cblk->passes = 0; -diff --git a/src/libjasper/jpc/jpc_t2cod.c b/src/libjasper/jpc/jpc_t2cod.c -index e734900..f3d030a 100644 ---- a/src/libjasper/jpc/jpc_t2cod.c -+++ b/src/libjasper/jpc/jpc_t2cod.c -@@ -573,7 +573,7 @@ int jpc_pchglist_insert(jpc_pchglist_t *pchglist, int pchgno, jpc_pchg_t *pchg) +--- a/src/libjasper/jpc/jpc_t2cod.c 2007-01-19 22:43:07.000000000 +0100 ++++ b/src/libjasper/jpc/jpc_t2cod.c 2015-01-28 17:57:34.128045603 +0100 +@@ -573,7 +573,7 @@ } if (pchglist->numpchgs >= pchglist->maxpchgs) { newmaxpchgs = pchglist->maxpchgs + 128; @@ -876,11 +940,9 @@ index e734900..f3d030a 100644 return -1; } pchglist->maxpchgs = newmaxpchgs; -diff --git a/src/libjasper/jpc/jpc_t2dec.c b/src/libjasper/jpc/jpc_t2dec.c -index 6d2cb72..8300f9b 100644 ---- a/src/libjasper/jpc/jpc_t2dec.c -+++ b/src/libjasper/jpc/jpc_t2dec.c -@@ -478,7 +478,7 @@ jpc_pi_t *jpc_dec_pi_create(jpc_dec_t *dec, jpc_dec_tile_t *tile) +--- a/src/libjasper/jpc/jpc_t2dec.c 2007-01-19 22:43:07.000000000 +0100 ++++ b/src/libjasper/jpc/jpc_t2dec.c 2015-01-28 17:57:34.129045620 +0100 +@@ -478,7 +478,7 @@ return 0; } pi->numcomps = dec->numcomps; @@ -889,7 +951,7 @@ index 6d2cb72..8300f9b 100644 jpc_pi_destroy(pi); return 0; } -@@ -490,7 +490,7 @@ jpc_pi_t *jpc_dec_pi_create(jpc_dec_t *dec, jpc_dec_tile_t *tile) +@@ -490,7 +490,7 @@ for (compno = 0, tcomp = tile->tcomps, picomp = pi->picomps; compno < pi->numcomps; ++compno, ++tcomp, ++picomp) { picomp->numrlvls = tcomp->numrlvls; @@ -898,7 +960,7 @@ index 6d2cb72..8300f9b 100644 sizeof(jpc_pirlvl_t)))) { jpc_pi_destroy(pi); return 0; -@@ -503,7 +503,7 @@ jpc_pi_t *jpc_dec_pi_create(jpc_dec_t *dec, jpc_dec_tile_t *tile) +@@ -503,7 +503,7 @@ rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) { /* XXX sizeof(long) should be sizeof different type */ pirlvl->numprcs = rlvl->numprcs; @@ -907,11 +969,9 @@ index 6d2cb72..8300f9b 100644 sizeof(long)))) { jpc_pi_destroy(pi); return 0; -diff --git a/src/libjasper/jpc/jpc_t2enc.c b/src/libjasper/jpc/jpc_t2enc.c -index 9358a1c..d96066f 100644 ---- a/src/libjasper/jpc/jpc_t2enc.c -+++ b/src/libjasper/jpc/jpc_t2enc.c -@@ -565,7 +565,7 @@ jpc_pi_t *jpc_enc_pi_create(jpc_enc_cp_t *cp, jpc_enc_tile_t *tile) +--- a/src/libjasper/jpc/jpc_t2enc.c 2007-01-19 22:43:07.000000000 +0100 ++++ b/src/libjasper/jpc/jpc_t2enc.c 2015-01-28 17:57:34.129045620 +0100 +@@ -565,7 +565,7 @@ } pi->pktno = -1; pi->numcomps = cp->numcmpts; @@ -920,7 +980,7 @@ index 9358a1c..d96066f 100644 jpc_pi_destroy(pi); return 0; } -@@ -577,7 +577,7 @@ jpc_pi_t *jpc_enc_pi_create(jpc_enc_cp_t *cp, jpc_enc_tile_t *tile) +@@ -577,7 +577,7 @@ for (compno = 0, tcomp = tile->tcmpts, picomp = pi->picomps; compno < pi->numcomps; ++compno, ++tcomp, ++picomp) { picomp->numrlvls = tcomp->numrlvls; @@ -929,7 +989,7 @@ index 9358a1c..d96066f 100644 sizeof(jpc_pirlvl_t)))) { jpc_pi_destroy(pi); return 0; -@@ -591,7 +591,7 @@ jpc_pi_t *jpc_enc_pi_create(jpc_enc_cp_t *cp, jpc_enc_tile_t *tile) +@@ -591,7 +591,7 @@ /* XXX sizeof(long) should be sizeof different type */ pirlvl->numprcs = rlvl->numprcs; if (rlvl->numprcs) { @@ -938,11 +998,9 @@ index 9358a1c..d96066f 100644 sizeof(long)))) { jpc_pi_destroy(pi); return 0; -diff --git a/src/libjasper/jpc/jpc_tagtree.c b/src/libjasper/jpc/jpc_tagtree.c -index 06422d3..8dce000 100644 ---- a/src/libjasper/jpc/jpc_tagtree.c -+++ b/src/libjasper/jpc/jpc_tagtree.c -@@ -125,7 +125,7 @@ jpc_tagtree_t *jpc_tagtree_create(int numleafsh, int numleafsv) +--- a/src/libjasper/jpc/jpc_tagtree.c 2007-01-19 22:43:07.000000000 +0100 ++++ b/src/libjasper/jpc/jpc_tagtree.c 2015-01-28 17:57:34.130045636 +0100 +@@ -125,7 +125,7 @@ ++numlvls; } while (n > 1); @@ -951,11 +1009,9 @@ index 06422d3..8dce000 100644 return 0; } -diff --git a/src/libjasper/jpc/jpc_util.c b/src/libjasper/jpc/jpc_util.c -index f53e248..6da1b66 100644 ---- a/src/libjasper/jpc/jpc_util.c -+++ b/src/libjasper/jpc/jpc_util.c -@@ -109,7 +109,7 @@ int jpc_atoaf(char *s, int *numvalues, double **values) +--- a/src/libjasper/jpc/jpc_util.c 2007-01-19 22:43:07.000000000 +0100 ++++ b/src/libjasper/jpc/jpc_util.c 2015-01-28 17:57:34.130045636 +0100 +@@ -109,7 +109,7 @@ } if (n) { @@ -964,11 +1020,9 @@ index f53e248..6da1b66 100644 return -1; } -diff --git a/src/libjasper/mif/mif_cod.c b/src/libjasper/mif/mif_cod.c -index 17506a1..a1b29dc 100644 ---- a/src/libjasper/mif/mif_cod.c -+++ b/src/libjasper/mif/mif_cod.c -@@ -438,8 +438,7 @@ static int mif_hdr_growcmpts(mif_hdr_t *hdr, int maxcmpts) +--- a/src/libjasper/mif/mif_cod.c 2007-01-19 22:43:05.000000000 +0100 ++++ b/src/libjasper/mif/mif_cod.c 2015-01-28 17:57:34.131045653 +0100 +@@ -438,8 +438,7 @@ int cmptno; mif_cmpt_t **newcmpts; assert(maxcmpts >= hdr->numcmpts); diff --git a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/base/jas_icc.c b/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/base/jas_icc.c index f5cc16b184..6f7cca29f5 100644 --- a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/base/jas_icc.c +++ b/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/base/jas_icc.c @@ -1017,7 +1017,6 @@ static int jas_icccurv_input(jas_iccattrval_t *attrval, jas_stream_t *in, return 0; error: - jas_icccurv_destroy(attrval); return -1; } @@ -1135,7 +1134,6 @@ static int jas_icctxtdesc_input(jas_iccattrval_t *attrval, jas_stream_t *in, #endif return 0; error: - jas_icctxtdesc_destroy(attrval); return -1; } @@ -1214,8 +1212,6 @@ static int jas_icctxt_input(jas_iccattrval_t *attrval, jas_stream_t *in, goto error; return 0; error: - if (txt->string) - jas_free(txt->string); return -1; } @@ -1336,7 +1332,6 @@ static int jas_icclut8_input(jas_iccattrval_t *attrval, jas_stream_t *in, goto error; return 0; error: - jas_icclut8_destroy(attrval); return -1; } @@ -1505,7 +1500,6 @@ static int jas_icclut16_input(jas_iccattrval_t *attrval, jas_stream_t *in, goto error; return 0; error: - jas_icclut16_destroy(attrval); return -1; } diff --git a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/base/jas_stream.c b/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/base/jas_stream.c index 578d046bfd..15aed502be 100644 --- a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/base/jas_stream.c +++ b/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/base/jas_stream.c @@ -368,22 +368,28 @@ jas_stream_t *jas_stream_tmpfile() } obj->fd = -1; obj->flags = 0; + obj->pathname[0] = '\0'; stream->obj_ = obj; /* Choose a file name. */ - snprintf(obj->pathname, L_tmpnam, "%stmp.XXXXXXXXXX", P_tmpdir); + tmpnam(obj->pathname); /* Open the underlying file. */ - if ((obj->fd = mkstemp(obj->pathname)) < 0) { + if ((obj->fd = open(obj->pathname, O_CREAT | O_EXCL | O_RDWR | O_TRUNC | O_BINARY, + JAS_STREAM_PERMS)) < 0) { jas_stream_destroy(stream); return 0; } /* Unlink the file so that it will disappear if the program terminates abnormally. */ + /* Under UNIX, one can unlink an open file and continue to do I/O + on it. Not all operating systems support this functionality, however. + For example, under Microsoft Windows the unlink operation will fail, + since the file is open. */ if (unlink(obj->pathname)) { - jas_stream_destroy(stream); - return 0; + /* We will try unlinking the file again after it is closed. */ + obj->flags |= JAS_STREAM_FILEOBJ_DELONCLOSE; } /* Use full buffering. */ diff --git a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jp2/jp2_cod.c b/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jp2/jp2_cod.c index 808e6f07bf..56908abf01 100644 --- a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jp2/jp2_cod.c +++ b/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jp2/jp2_cod.c @@ -254,7 +254,7 @@ jp2_box_t *jp2_box_get(jas_stream_t *in) box = 0; tmpstream = 0; - if (!(box = jas_malloc(sizeof(jp2_box_t)))) { + if (!(box = jas_calloc(1, sizeof(jp2_box_t)))) { goto error; } box->ops = &jp2_boxinfo_unk.ops; diff --git a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jp2/jp2_cod.c.orig b/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jp2/jp2_cod.c.orig deleted file mode 100644 index 83cecb1f91..0000000000 --- a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jp2/jp2_cod.c.orig +++ /dev/null @@ -1,921 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer License Version 2.0 - * - * Copyright (c) 2001-2006 Michael David Adams - * Copyright (c) 1999-2000 Image Power, Inc. - * Copyright (c) 1999-2000 The University of British Columbia - * - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person (the - * "User") obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, and/or sell copies of the Software, and to permit - * persons to whom the Software is furnished to do so, subject to the - * following conditions: - * - * 1. The above copyright notices and this permission notice (which - * includes the disclaimer below) shall be included in all copies or - * substantial portions of the Software. - * - * 2. The name of a copyright holder shall not be used to endorse or - * promote products derived from the Software without specific prior - * written permission. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS - * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS - * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL - * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE - * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE - * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY. - * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS - * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL - * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS - * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE - * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE - * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL - * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL - * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH - * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH, - * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH - * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY - * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * JP2 Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include - -#include "jasper/jas_stream.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_debug.h" - -#include "jp2_cod.h" - -/******************************************************************************\ -* Function prototypes. -\******************************************************************************/ - -#define ONES(n) ((1 << (n)) - 1) - -jp2_boxinfo_t *jp2_boxinfolookup(int type); - -static int jp2_getuint8(jas_stream_t *in, uint_fast8_t *val); -static int jp2_getuint16(jas_stream_t *in, uint_fast16_t *val); -static int jp2_getuint32(jas_stream_t *in, uint_fast32_t *val); -static int jp2_getuint64(jas_stream_t *in, uint_fast64_t *val); -static int jp2_putuint8(jas_stream_t *out, uint_fast8_t val); -static int jp2_putuint16(jas_stream_t *out, uint_fast16_t val); -static int jp2_putuint32(jas_stream_t *out, uint_fast32_t val); -static int jp2_putuint64(jas_stream_t *out, uint_fast64_t val); - -static int jp2_getint(jas_stream_t *in, int s, int n, int_fast32_t *val); - -jp2_box_t *jp2_box_get(jas_stream_t *in); -void jp2_box_dump(jp2_box_t *box, FILE *out); - -static int jp2_jp_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_jp_putdata(jp2_box_t *box, jas_stream_t *out); -static int jp2_ftyp_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_ftyp_putdata(jp2_box_t *box, jas_stream_t *out); -static int jp2_ihdr_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_ihdr_putdata(jp2_box_t *box, jas_stream_t *out); -static void jp2_bpcc_destroy(jp2_box_t *box); -static int jp2_bpcc_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_bpcc_putdata(jp2_box_t *box, jas_stream_t *out); -static int jp2_colr_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_colr_putdata(jp2_box_t *box, jas_stream_t *out); -static void jp2_colr_dumpdata(jp2_box_t *box, FILE *out); -static void jp2_colr_destroy(jp2_box_t *box); -static void jp2_cdef_destroy(jp2_box_t *box); -static int jp2_cdef_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_cdef_putdata(jp2_box_t *box, jas_stream_t *out); -static void jp2_cdef_dumpdata(jp2_box_t *box, FILE *out); -static void jp2_cmap_destroy(jp2_box_t *box); -static int jp2_cmap_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_cmap_putdata(jp2_box_t *box, jas_stream_t *out); -static void jp2_cmap_dumpdata(jp2_box_t *box, FILE *out); -static void jp2_pclr_destroy(jp2_box_t *box); -static int jp2_pclr_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_pclr_putdata(jp2_box_t *box, jas_stream_t *out); -static void jp2_pclr_dumpdata(jp2_box_t *box, FILE *out); - -/******************************************************************************\ -* Local data. -\******************************************************************************/ - -jp2_boxinfo_t jp2_boxinfos[] = { - {JP2_BOX_JP, "JP", 0, - {0, 0, jp2_jp_getdata, jp2_jp_putdata, 0}}, - {JP2_BOX_FTYP, "FTYP", 0, - {0, 0, jp2_ftyp_getdata, jp2_ftyp_putdata, 0}}, - {JP2_BOX_JP2H, "JP2H", JP2_BOX_SUPER, - {0, 0, 0, 0, 0}}, - {JP2_BOX_IHDR, "IHDR", 0, - {0, 0, jp2_ihdr_getdata, jp2_ihdr_putdata, 0}}, - {JP2_BOX_BPCC, "BPCC", 0, - {0, jp2_bpcc_destroy, jp2_bpcc_getdata, jp2_bpcc_putdata, 0}}, - {JP2_BOX_COLR, "COLR", 0, - {0, jp2_colr_destroy, jp2_colr_getdata, jp2_colr_putdata, jp2_colr_dumpdata}}, - {JP2_BOX_PCLR, "PCLR", 0, - {0, jp2_pclr_destroy, jp2_pclr_getdata, jp2_pclr_putdata, jp2_pclr_dumpdata}}, - {JP2_BOX_CMAP, "CMAP", 0, - {0, jp2_cmap_destroy, jp2_cmap_getdata, jp2_cmap_putdata, jp2_cmap_dumpdata}}, - {JP2_BOX_CDEF, "CDEF", 0, - {0, jp2_cdef_destroy, jp2_cdef_getdata, jp2_cdef_putdata, jp2_cdef_dumpdata}}, - {JP2_BOX_RES, "RES", JP2_BOX_SUPER, - {0, 0, 0, 0, 0}}, - {JP2_BOX_RESC, "RESC", 0, - {0, 0, 0, 0, 0}}, - {JP2_BOX_RESD, "RESD", 0, - {0, 0, 0, 0, 0}}, - {JP2_BOX_JP2C, "JP2C", JP2_BOX_NODATA, - {0, 0, 0, 0, 0}}, - {JP2_BOX_JP2I, "JP2I", 0, - {0, 0, 0, 0, 0}}, - {JP2_BOX_XML, "XML", 0, - {0, 0, 0, 0, 0}}, - {JP2_BOX_UUID, "UUID", 0, - {0, 0, 0, 0, 0}}, - {JP2_BOX_UINF, "UINF", JP2_BOX_SUPER, - {0, 0, 0, 0, 0}}, - {JP2_BOX_ULST, "ULST", 0, - {0, 0, 0, 0, 0}}, - {JP2_BOX_URL, "URL", 0, - {0, 0, 0, 0, 0}}, - {0, 0, 0, {0, 0, 0, 0, 0}}, -}; - -jp2_boxinfo_t jp2_boxinfo_unk = { - 0, "Unknown", 0, {0, 0, 0, 0, 0} -}; - -/******************************************************************************\ -* Box constructor. -\******************************************************************************/ - -jp2_box_t *jp2_box_create(int type) -{ - jp2_box_t *box; - jp2_boxinfo_t *boxinfo; - - if (!(box = jas_malloc(sizeof(jp2_box_t)))) { - return 0; - } - memset(box, 0, sizeof(jp2_box_t)); - box->type = type; - box->len = 0; - if (!(boxinfo = jp2_boxinfolookup(type))) { - return 0; - } - box->info = boxinfo; - box->ops = &boxinfo->ops; - return box; -} - -/******************************************************************************\ -* Box destructor. -\******************************************************************************/ - -void jp2_box_destroy(jp2_box_t *box) -{ - if (box->ops->destroy) { - (*box->ops->destroy)(box); - } - jas_free(box); -} - -static void jp2_bpcc_destroy(jp2_box_t *box) -{ - jp2_bpcc_t *bpcc = &box->data.bpcc; - if (bpcc->bpcs) { - jas_free(bpcc->bpcs); - bpcc->bpcs = 0; - } -} - -static void jp2_cdef_destroy(jp2_box_t *box) -{ - jp2_cdef_t *cdef = &box->data.cdef; - if (cdef->ents) { - jas_free(cdef->ents); - cdef->ents = 0; - } -} - -/******************************************************************************\ -* Box input. -\******************************************************************************/ - -jp2_box_t *jp2_box_get(jas_stream_t *in) -{ - jp2_box_t *box; - jp2_boxinfo_t *boxinfo; - jas_stream_t *tmpstream; - uint_fast32_t len; - uint_fast64_t extlen; - bool dataflag; - - box = 0; - tmpstream = 0; - - if (!(box = jas_malloc(sizeof(jp2_box_t)))) { - goto error; - } - box->ops = &jp2_boxinfo_unk.ops; - if (jp2_getuint32(in, &len) || jp2_getuint32(in, &box->type)) { - goto error; - } - boxinfo = jp2_boxinfolookup(box->type); - box->info = boxinfo; - box->ops = &boxinfo->ops; - box->len = len; - if (box->len == 1) { - if (jp2_getuint64(in, &extlen)) { - goto error; - } - if (extlen > 0xffffffffUL) { - jas_eprintf("warning: cannot handle large 64-bit box length\n"); - extlen = 0xffffffffUL; - } - box->len = extlen; - box->datalen = extlen - JP2_BOX_HDRLEN(true); - } else { - box->datalen = box->len - JP2_BOX_HDRLEN(false); - } - if (box->len != 0 && box->len < 8) { - goto error; - } - - dataflag = !(box->info->flags & (JP2_BOX_SUPER | JP2_BOX_NODATA)); - - if (dataflag) { - if (!(tmpstream = jas_stream_memopen(0, 0))) { - goto error; - } - if (jas_stream_copy(tmpstream, in, box->datalen)) { - jas_eprintf("cannot copy box data\n"); - goto error; - } - jas_stream_rewind(tmpstream); - - if (box->ops->getdata) { - if ((*box->ops->getdata)(box, tmpstream)) { - jas_eprintf("cannot parse box data\n"); - goto error; - } - } - jas_stream_close(tmpstream); - } - - if (jas_getdbglevel() >= 1) { - jp2_box_dump(box, stderr); - } - - return box; - abort(); - -error: - if (box) { - jp2_box_destroy(box); - } - if (tmpstream) { - jas_stream_close(tmpstream); - } - return 0; -} - -void jp2_box_dump(jp2_box_t *box, FILE *out) -{ - jp2_boxinfo_t *boxinfo; - boxinfo = jp2_boxinfolookup(box->type); - assert(boxinfo); - - fprintf(out, "JP2 box: "); - fprintf(out, "type=%c%s%c (0x%08x); length=%d\n", '"', boxinfo->name, - '"', box->type, box->len); - if (box->ops->dumpdata) { - (*box->ops->dumpdata)(box, out); - } -} - -static int jp2_jp_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_jp_t *jp = &box->data.jp; - if (jp2_getuint32(in, &jp->magic)) { - return -1; - } - return 0; -} - -static int jp2_ftyp_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_ftyp_t *ftyp = &box->data.ftyp; - unsigned int i; - if (jp2_getuint32(in, &ftyp->majver) || jp2_getuint32(in, &ftyp->minver)) { - return -1; - } - ftyp->numcompatcodes = (box->datalen - 8) / 4; - if (ftyp->numcompatcodes > JP2_FTYP_MAXCOMPATCODES) { - return -1; - } - for (i = 0; i < ftyp->numcompatcodes; ++i) { - if (jp2_getuint32(in, &ftyp->compatcodes[i])) { - return -1; - } - } - return 0; -} - -static int jp2_ihdr_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_ihdr_t *ihdr = &box->data.ihdr; - if (jp2_getuint32(in, &ihdr->height) || jp2_getuint32(in, &ihdr->width) || - jp2_getuint16(in, &ihdr->numcmpts) || jp2_getuint8(in, &ihdr->bpc) || - jp2_getuint8(in, &ihdr->comptype) || jp2_getuint8(in, &ihdr->csunk) || - jp2_getuint8(in, &ihdr->ipr)) { - return -1; - } - return 0; -} - -static int jp2_bpcc_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_bpcc_t *bpcc = &box->data.bpcc; - unsigned int i; - bpcc->numcmpts = box->datalen; - if (!(bpcc->bpcs = jas_malloc(bpcc->numcmpts * sizeof(uint_fast8_t)))) { - return -1; - } - for (i = 0; i < bpcc->numcmpts; ++i) { - if (jp2_getuint8(in, &bpcc->bpcs[i])) { - return -1; - } - } - return 0; -} - -static void jp2_colr_dumpdata(jp2_box_t *box, FILE *out) -{ - jp2_colr_t *colr = &box->data.colr; - fprintf(out, "method=%d; pri=%d; approx=%d\n", (int)colr->method, (int)colr->pri, (int)colr->approx); - switch (colr->method) { - case JP2_COLR_ENUM: - fprintf(out, "csid=%d\n", (int)colr->csid); - break; - case JP2_COLR_ICC: - jas_memdump(out, colr->iccp, colr->iccplen); - break; - } -} - -static int jp2_colr_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_colr_t *colr = &box->data.colr; - colr->csid = 0; - colr->iccp = 0; - colr->iccplen = 0; - - if (jp2_getuint8(in, &colr->method) || jp2_getuint8(in, &colr->pri) || - jp2_getuint8(in, &colr->approx)) { - return -1; - } - switch (colr->method) { - case JP2_COLR_ENUM: - if (jp2_getuint32(in, &colr->csid)) { - return -1; - } - break; - case JP2_COLR_ICC: - colr->iccplen = box->datalen - 3; - if (!(colr->iccp = jas_malloc(colr->iccplen * sizeof(uint_fast8_t)))) { - return -1; - } - if (jas_stream_read(in, colr->iccp, colr->iccplen) != colr->iccplen) { - return -1; - } - break; - } - return 0; -} - -static void jp2_cdef_dumpdata(jp2_box_t *box, FILE *out) -{ - jp2_cdef_t *cdef = &box->data.cdef; - unsigned int i; - for (i = 0; i < cdef->numchans; ++i) { - fprintf(out, "channo=%d; type=%d; assoc=%d\n", - cdef->ents[i].channo, cdef->ents[i].type, cdef->ents[i].assoc); - } -} - -static void jp2_colr_destroy(jp2_box_t *box) -{ - jp2_colr_t *colr = &box->data.colr; - if (colr->iccp) { - jas_free(colr->iccp); - } -} - -static int jp2_cdef_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_cdef_t *cdef = &box->data.cdef; - jp2_cdefchan_t *chan; - unsigned int channo; - if (jp2_getuint16(in, &cdef->numchans)) { - return -1; - } - if (!(cdef->ents = jas_malloc(cdef->numchans * sizeof(jp2_cdefchan_t)))) { - return -1; - } - for (channo = 0; channo < cdef->numchans; ++channo) { - chan = &cdef->ents[channo]; - if (jp2_getuint16(in, &chan->channo) || jp2_getuint16(in, &chan->type) || - jp2_getuint16(in, &chan->assoc)) { - return -1; - } - } - return 0; -} - -/******************************************************************************\ -* Box output. -\******************************************************************************/ - -int jp2_box_put(jp2_box_t *box, jas_stream_t *out) -{ - jas_stream_t *tmpstream; - bool extlen; - bool dataflag; - - tmpstream = 0; - - dataflag = !(box->info->flags & (JP2_BOX_SUPER | JP2_BOX_NODATA)); - - if (dataflag) { - tmpstream = jas_stream_memopen(0, 0); - if (box->ops->putdata) { - if ((*box->ops->putdata)(box, tmpstream)) { - goto error; - } - } - box->len = jas_stream_tell(tmpstream) + JP2_BOX_HDRLEN(false); - jas_stream_rewind(tmpstream); - } - extlen = (box->len >= (((uint_fast64_t)1) << 32)) != 0; - if (jp2_putuint32(out, extlen ? 1 : box->len)) { - goto error; - } - if (jp2_putuint32(out, box->type)) { - goto error; - } - if (extlen) { - if (jp2_putuint64(out, box->len)) { - goto error; - } - } - - if (dataflag) { - if (jas_stream_copy(out, tmpstream, box->len - JP2_BOX_HDRLEN(false))) { - goto error; - } - jas_stream_close(tmpstream); - } - - return 0; - abort(); - -error: - - if (tmpstream) { - jas_stream_close(tmpstream); - } - return -1; -} - -static int jp2_jp_putdata(jp2_box_t *box, jas_stream_t *out) -{ - jp2_jp_t *jp = &box->data.jp; - if (jp2_putuint32(out, jp->magic)) { - return -1; - } - return 0; -} - -static int jp2_ftyp_putdata(jp2_box_t *box, jas_stream_t *out) -{ - jp2_ftyp_t *ftyp = &box->data.ftyp; - unsigned int i; - if (jp2_putuint32(out, ftyp->majver) || jp2_putuint32(out, ftyp->minver)) { - return -1; - } - for (i = 0; i < ftyp->numcompatcodes; ++i) { - if (jp2_putuint32(out, ftyp->compatcodes[i])) { - return -1; - } - } - return 0; -} - -static int jp2_ihdr_putdata(jp2_box_t *box, jas_stream_t *out) -{ - jp2_ihdr_t *ihdr = &box->data.ihdr; - if (jp2_putuint32(out, ihdr->height) || jp2_putuint32(out, ihdr->width) || - jp2_putuint16(out, ihdr->numcmpts) || jp2_putuint8(out, ihdr->bpc) || - jp2_putuint8(out, ihdr->comptype) || jp2_putuint8(out, ihdr->csunk) || - jp2_putuint8(out, ihdr->ipr)) { - return -1; - } - return 0; -} - -static int jp2_bpcc_putdata(jp2_box_t *box, jas_stream_t *out) -{ - jp2_bpcc_t *bpcc = &box->data.bpcc; - unsigned int i; - for (i = 0; i < bpcc->numcmpts; ++i) { - if (jp2_putuint8(out, bpcc->bpcs[i])) { - return -1; - } - } - return 0; -} - -static int jp2_colr_putdata(jp2_box_t *box, jas_stream_t *out) -{ - jp2_colr_t *colr = &box->data.colr; - if (jp2_putuint8(out, colr->method) || jp2_putuint8(out, colr->pri) || - jp2_putuint8(out, colr->approx)) { - return -1; - } - switch (colr->method) { - case JP2_COLR_ENUM: - if (jp2_putuint32(out, colr->csid)) { - return -1; - } - break; - case JP2_COLR_ICC: - if (jas_stream_write(out, colr->iccp, - JAS_CAST(int, colr->iccplen)) != JAS_CAST(int, colr->iccplen)) - return -1; - break; - } - return 0; -} - -static int jp2_cdef_putdata(jp2_box_t *box, jas_stream_t *out) -{ - jp2_cdef_t *cdef = &box->data.cdef; - unsigned int i; - jp2_cdefchan_t *ent; - - if (jp2_putuint16(out, cdef->numchans)) { - return -1; - } - - for (i = 0; i < cdef->numchans; ++i) { - ent = &cdef->ents[i]; - if (jp2_putuint16(out, ent->channo) || - jp2_putuint16(out, ent->type) || - jp2_putuint16(out, ent->assoc)) { - return -1; - } - } - return 0; -} - -/******************************************************************************\ -* Input operations for primitive types. -\******************************************************************************/ - -static int jp2_getuint8(jas_stream_t *in, uint_fast8_t *val) -{ - int c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - if (val) { - *val = c; - } - return 0; -} - -static int jp2_getuint16(jas_stream_t *in, uint_fast16_t *val) -{ - uint_fast16_t v; - int c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = (v << 8) | c; - if (val) { - *val = v; - } - return 0; -} - -static int jp2_getuint32(jas_stream_t *in, uint_fast32_t *val) -{ - uint_fast32_t v; - int c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = (v << 8) | c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = (v << 8) | c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = (v << 8) | c; - if (val) { - *val = v; - } - return 0; -} - -static int jp2_getuint64(jas_stream_t *in, uint_fast64_t *val) -{ - uint_fast64_t tmpval; - int i; - int c; - - tmpval = 0; - for (i = 0; i < 8; ++i) { - tmpval <<= 8; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - tmpval |= (c & 0xff); - } - *val = tmpval; - - return 0; -} - -/******************************************************************************\ -* Output operations for primitive types. -\******************************************************************************/ - -static int jp2_putuint8(jas_stream_t *out, uint_fast8_t val) -{ - if (jas_stream_putc(out, val & 0xff) == EOF) { - return -1; - } - return 0; -} - -static int jp2_putuint16(jas_stream_t *out, uint_fast16_t val) -{ - if (jas_stream_putc(out, (val >> 8) & 0xff) == EOF || - jas_stream_putc(out, val & 0xff) == EOF) { - return -1; - } - return 0; -} - -static int jp2_putuint32(jas_stream_t *out, uint_fast32_t val) -{ - if (jas_stream_putc(out, (val >> 24) & 0xff) == EOF || - jas_stream_putc(out, (val >> 16) & 0xff) == EOF || - jas_stream_putc(out, (val >> 8) & 0xff) == EOF || - jas_stream_putc(out, val & 0xff) == EOF) { - return -1; - } - return 0; -} - -static int jp2_putuint64(jas_stream_t *out, uint_fast64_t val) -{ - if (jp2_putuint32(out, (val >> 32) & 0xffffffffUL) || - jp2_putuint32(out, val & 0xffffffffUL)) { - return -1; - } - return 0; -} - -/******************************************************************************\ -* Miscellaneous code. -\******************************************************************************/ - -jp2_boxinfo_t *jp2_boxinfolookup(int type) -{ - jp2_boxinfo_t *boxinfo; - for (boxinfo = jp2_boxinfos; boxinfo->name; ++boxinfo) { - if (boxinfo->type == type) { - return boxinfo; - } - } - return &jp2_boxinfo_unk; -} - - - - - -static void jp2_cmap_destroy(jp2_box_t *box) -{ - jp2_cmap_t *cmap = &box->data.cmap; - if (cmap->ents) { - jas_free(cmap->ents); - } -} - -static int jp2_cmap_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_cmap_t *cmap = &box->data.cmap; - jp2_cmapent_t *ent; - unsigned int i; - - cmap->numchans = (box->datalen) / 4; - if (!(cmap->ents = jas_malloc(cmap->numchans * sizeof(jp2_cmapent_t)))) { - return -1; - } - for (i = 0; i < cmap->numchans; ++i) { - ent = &cmap->ents[i]; - if (jp2_getuint16(in, &ent->cmptno) || - jp2_getuint8(in, &ent->map) || - jp2_getuint8(in, &ent->pcol)) { - return -1; - } - } - - return 0; -} - -static int jp2_cmap_putdata(jp2_box_t *box, jas_stream_t *out) -{ - /* Eliminate compiler warning about unused variables. */ - box = 0; - out = 0; - - return -1; -} - -static void jp2_cmap_dumpdata(jp2_box_t *box, FILE *out) -{ - jp2_cmap_t *cmap = &box->data.cmap; - unsigned int i; - jp2_cmapent_t *ent; - fprintf(out, "numchans = %d\n", (int) cmap->numchans); - for (i = 0; i < cmap->numchans; ++i) { - ent = &cmap->ents[i]; - fprintf(out, "cmptno=%d; map=%d; pcol=%d\n", - (int) ent->cmptno, (int) ent->map, (int) ent->pcol); - } -} - -static void jp2_pclr_destroy(jp2_box_t *box) -{ - jp2_pclr_t *pclr = &box->data.pclr; - if (pclr->lutdata) { - jas_free(pclr->lutdata); - } - if (pclr->bpc) - jas_free(pclr->bpc); -} - -static int jp2_pclr_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_pclr_t *pclr = &box->data.pclr; - int lutsize; - unsigned int i; - unsigned int j; - int_fast32_t x; - - pclr->lutdata = 0; - - if (jp2_getuint16(in, &pclr->numlutents) || - jp2_getuint8(in, &pclr->numchans)) { - return -1; - } - lutsize = pclr->numlutents * pclr->numchans; - if (!(pclr->lutdata = jas_malloc(lutsize * sizeof(int_fast32_t)))) { - return -1; - } - if (!(pclr->bpc = jas_malloc(pclr->numchans * sizeof(uint_fast8_t)))) { - return -1; - } - for (i = 0; i < pclr->numchans; ++i) { - if (jp2_getuint8(in, &pclr->bpc[i])) { - return -1; - } - } - for (i = 0; i < pclr->numlutents; ++i) { - for (j = 0; j < pclr->numchans; ++j) { - if (jp2_getint(in, (pclr->bpc[j] & 0x80) != 0, - (pclr->bpc[j] & 0x7f) + 1, &x)) { - return -1; - } - pclr->lutdata[i * pclr->numchans + j] = x; - } - } - return 0; -} - -static int jp2_pclr_putdata(jp2_box_t *box, jas_stream_t *out) -{ -#if 0 - jp2_pclr_t *pclr = &box->data.pclr; -#endif -/* Eliminate warning about unused variable. */ -box = 0; -out = 0; - return -1; -} - -static void jp2_pclr_dumpdata(jp2_box_t *box, FILE *out) -{ - jp2_pclr_t *pclr = &box->data.pclr; - unsigned int i; - int j; - fprintf(out, "numents=%d; numchans=%d\n", (int) pclr->numlutents, - (int) pclr->numchans); - for (i = 0; i < pclr->numlutents; ++i) { - for (j = 0; j < pclr->numchans; ++j) { - fprintf(out, "LUT[%d][%d]=%d\n", i, j, pclr->lutdata[i * pclr->numchans + j]); - } - } -} - -static int jp2_getint(jas_stream_t *in, int s, int n, int_fast32_t *val) -{ - int c; - int i; - uint_fast32_t v; - int m; - - m = (n + 7) / 8; - - v = 0; - for (i = 0; i < m; ++i) { - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = (v << 8) | c; - } - v &= ONES(n); - if (s) { - int sb; - sb = v & (1 << (8 * m - 1)); - *val = ((~v) + 1) & ONES(8 * m); - if (sb) { - *val = -*val; - } - } else { - *val = v; - } - - return 0; -} - -jp2_cdefchan_t *jp2_cdef_lookup(jp2_cdef_t *cdef, int channo) -{ - unsigned int i; - jp2_cdefchan_t *cdefent; - for (i = 0; i < cdef->numchans; ++i) { - cdefent = &cdef->ents[i]; - if (cdefent->channo == JAS_CAST(unsigned int, channo)) { - return cdefent; - } - } - return 0; -} diff --git a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jp2/jp2_dec.c b/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jp2/jp2_dec.c index d912cb9fa8..857b92dedf 100644 --- a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jp2/jp2_dec.c +++ b/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jp2/jp2_dec.c @@ -298,7 +298,10 @@ jas_image_t *jp2_decode(jas_stream_t *in, char *optstr) case JP2_COLR_ICC: iccprof = jas_iccprof_createfrombuf(dec->colr->data.colr.iccp, dec->colr->data.colr.iccplen); - assert(iccprof); + if (!iccprof) { + jas_eprintf("error: failed to parse ICC profile\n"); + goto error; + } jas_iccprof_gethdr(iccprof, &icchdr); jas_eprintf("ICC Profile CS %08x\n", icchdr.colorspc); jas_image_setclrspc(dec->image, fromiccpcs(icchdr.colorspc)); @@ -393,6 +396,11 @@ jas_image_t *jp2_decode(jas_stream_t *in, char *optstr) /* Determine the type of each component. */ if (dec->cdef) { for (i = 0; i < dec->numchans; ++i) { + /* Is the channel number reasonable? */ + if (dec->cdef->data.cdef.ents[i].channo >= dec->numchans) { + jas_eprintf("error: invalid channel number in CDEF box\n"); + goto error; + } jas_image_setcmpttype(dec->image, dec->chantocmptlut[dec->cdef->data.cdef.ents[i].channo], jp2_getct(jas_image_clrspc(dec->image), diff --git a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jp2/jp2_enc.c.orig b/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jp2/jp2_enc.c.orig deleted file mode 100644 index 9e1e1fc47d..0000000000 --- a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jp2/jp2_enc.c.orig +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2003 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer License Version 2.0 - * - * Copyright (c) 2001-2006 Michael David Adams - * Copyright (c) 1999-2000 Image Power, Inc. - * Copyright (c) 1999-2000 The University of British Columbia - * - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person (the - * "User") obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, and/or sell copies of the Software, and to permit - * persons to whom the Software is furnished to do so, subject to the - * following conditions: - * - * 1. The above copyright notices and this permission notice (which - * includes the disclaimer below) shall be included in all copies or - * substantial portions of the Software. - * - * 2. The name of a copyright holder shall not be used to endorse or - * promote products derived from the Software without specific prior - * written permission. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS - * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS - * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL - * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE - * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE - * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY. - * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS - * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL - * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS - * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE - * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE - * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL - * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL - * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH - * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH, - * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH - * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY - * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * JP2 Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include "jasper/jas_malloc.h" -#include "jasper/jas_image.h" -#include "jasper/jas_stream.h" -#include "jasper/jas_cm.h" -#include "jasper/jas_icc.h" -#include "jp2_cod.h" - -static uint_fast32_t jp2_gettypeasoc(int colorspace, int ctype); -static int clrspctojp2(jas_clrspc_t clrspc); - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -int jp2_encode(jas_image_t *image, jas_stream_t *out, char *optstr) -{ - jp2_box_t *box; - jp2_ftyp_t *ftyp; - jp2_ihdr_t *ihdr; - jas_stream_t *tmpstream; - int allcmptssame; - jp2_bpcc_t *bpcc; - long len; - uint_fast16_t cmptno; - jp2_colr_t *colr; - char buf[4096]; - uint_fast32_t overhead; - jp2_cdefchan_t *cdefchanent; - jp2_cdef_t *cdef; - int i; - uint_fast32_t typeasoc; -jas_iccprof_t *iccprof; -jas_stream_t *iccstream; -int pos; -int needcdef; -int prec; -int sgnd; - - box = 0; - tmpstream = 0; - - allcmptssame = 1; - sgnd = jas_image_cmptsgnd(image, 0); - prec = jas_image_cmptprec(image, 0); - for (i = 1; i < jas_image_numcmpts(image); ++i) { - if (jas_image_cmptsgnd(image, i) != sgnd || - jas_image_cmptprec(image, i) != prec) { - allcmptssame = 0; - break; - } - } - - /* Output the signature box. */ - - if (!(box = jp2_box_create(JP2_BOX_JP))) { - goto error; - } - box->data.jp.magic = JP2_JP_MAGIC; - if (jp2_box_put(box, out)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - - /* Output the file type box. */ - - if (!(box = jp2_box_create(JP2_BOX_FTYP))) { - goto error; - } - ftyp = &box->data.ftyp; - ftyp->majver = JP2_FTYP_MAJVER; - ftyp->minver = JP2_FTYP_MINVER; - ftyp->numcompatcodes = 1; - ftyp->compatcodes[0] = JP2_FTYP_COMPATCODE; - if (jp2_box_put(box, out)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - - /* - * Generate the data portion of the JP2 header box. - * We cannot simply output the header for this box - * since we do not yet know the correct value for the length - * field. - */ - - if (!(tmpstream = jas_stream_memopen(0, 0))) { - goto error; - } - - /* Generate image header box. */ - - if (!(box = jp2_box_create(JP2_BOX_IHDR))) { - goto error; - } - ihdr = &box->data.ihdr; - ihdr->width = jas_image_width(image); - ihdr->height = jas_image_height(image); - ihdr->numcmpts = jas_image_numcmpts(image); - ihdr->bpc = allcmptssame ? JP2_SPTOBPC(jas_image_cmptsgnd(image, 0), - jas_image_cmptprec(image, 0)) : JP2_IHDR_BPCNULL; - ihdr->comptype = JP2_IHDR_COMPTYPE; - ihdr->csunk = 0; - ihdr->ipr = 0; - if (jp2_box_put(box, tmpstream)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - - /* Generate bits per component box. */ - - if (!allcmptssame) { - if (!(box = jp2_box_create(JP2_BOX_BPCC))) { - goto error; - } - bpcc = &box->data.bpcc; - bpcc->numcmpts = jas_image_numcmpts(image); - if (!(bpcc->bpcs = jas_malloc(bpcc->numcmpts * - sizeof(uint_fast8_t)))) { - goto error; - } - for (cmptno = 0; cmptno < bpcc->numcmpts; ++cmptno) { - bpcc->bpcs[cmptno] = JP2_SPTOBPC(jas_image_cmptsgnd(image, - cmptno), jas_image_cmptprec(image, cmptno)); - } - if (jp2_box_put(box, tmpstream)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - } - - /* Generate color specification box. */ - - if (!(box = jp2_box_create(JP2_BOX_COLR))) { - goto error; - } - colr = &box->data.colr; - switch (jas_image_clrspc(image)) { - case JAS_CLRSPC_SRGB: - case JAS_CLRSPC_SYCBCR: - case JAS_CLRSPC_SGRAY: - colr->method = JP2_COLR_ENUM; - colr->csid = clrspctojp2(jas_image_clrspc(image)); - colr->pri = JP2_COLR_PRI; - colr->approx = 0; - break; - default: - colr->method = JP2_COLR_ICC; - colr->pri = JP2_COLR_PRI; - colr->approx = 0; - iccprof = jas_iccprof_createfromcmprof(jas_image_cmprof(image)); - assert(iccprof); - iccstream = jas_stream_memopen(0, 0); - assert(iccstream); - if (jas_iccprof_save(iccprof, iccstream)) - abort(); - if ((pos = jas_stream_tell(iccstream)) < 0) - abort(); - colr->iccplen = pos; - colr->iccp = jas_malloc(pos); - assert(colr->iccp); - jas_stream_rewind(iccstream); - if (jas_stream_read(iccstream, colr->iccp, colr->iccplen) != colr->iccplen) - abort(); - jas_stream_close(iccstream); - jas_iccprof_destroy(iccprof); - break; - } - if (jp2_box_put(box, tmpstream)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - - needcdef = 1; - switch (jas_clrspc_fam(jas_image_clrspc(image))) { - case JAS_CLRSPC_FAM_RGB: - if (jas_image_cmpttype(image, 0) == - JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_R) && - jas_image_cmpttype(image, 1) == - JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_G) && - jas_image_cmpttype(image, 2) == - JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_B)) - needcdef = 0; - break; - case JAS_CLRSPC_FAM_YCBCR: - if (jas_image_cmpttype(image, 0) == - JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_Y) && - jas_image_cmpttype(image, 1) == - JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_CB) && - jas_image_cmpttype(image, 2) == - JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_CR)) - needcdef = 0; - break; - case JAS_CLRSPC_FAM_GRAY: - if (jas_image_cmpttype(image, 0) == - JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_GRAY_Y)) - needcdef = 0; - break; - default: - abort(); - break; - } - - if (needcdef) { - if (!(box = jp2_box_create(JP2_BOX_CDEF))) { - goto error; - } - cdef = &box->data.cdef; - cdef->numchans = jas_image_numcmpts(image); - cdef->ents = jas_malloc(cdef->numchans * sizeof(jp2_cdefchan_t)); - for (i = 0; i < jas_image_numcmpts(image); ++i) { - cdefchanent = &cdef->ents[i]; - cdefchanent->channo = i; - typeasoc = jp2_gettypeasoc(jas_image_clrspc(image), jas_image_cmpttype(image, i)); - cdefchanent->type = typeasoc >> 16; - cdefchanent->assoc = typeasoc & 0x7fff; - } - if (jp2_box_put(box, tmpstream)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - } - - /* Determine the total length of the JP2 header box. */ - - len = jas_stream_tell(tmpstream); - jas_stream_rewind(tmpstream); - - /* - * Output the JP2 header box and all of the boxes which it contains. - */ - - if (!(box = jp2_box_create(JP2_BOX_JP2H))) { - goto error; - } - box->len = len + JP2_BOX_HDRLEN(false); - if (jp2_box_put(box, out)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - - if (jas_stream_copy(out, tmpstream, len)) { - goto error; - } - - jas_stream_close(tmpstream); - tmpstream = 0; - - /* - * Output the contiguous code stream box. - */ - - if (!(box = jp2_box_create(JP2_BOX_JP2C))) { - goto error; - } - box->len = 0; - if (jp2_box_put(box, out)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - - /* Output the JPEG-2000 code stream. */ - - overhead = jas_stream_getrwcount(out); - sprintf(buf, "%s\n_jp2overhead=%lu\n", (optstr ? optstr : ""), - (unsigned long) overhead); - - if (jpc_encode(image, out, buf)) { - goto error; - } - - return 0; - abort(); - -error: - - if (box) { - jp2_box_destroy(box); - } - if (tmpstream) { - jas_stream_close(tmpstream); - } - return -1; -} - -static uint_fast32_t jp2_gettypeasoc(int colorspace, int ctype) -{ - int type; - int asoc; - - if (ctype & JAS_IMAGE_CT_OPACITY) { - type = JP2_CDEF_TYPE_OPACITY; - asoc = JP2_CDEF_ASOC_ALL; - goto done; - } - - type = JP2_CDEF_TYPE_UNSPEC; - asoc = JP2_CDEF_ASOC_NONE; - switch (jas_clrspc_fam(colorspace)) { - case JAS_CLRSPC_FAM_RGB: - switch (JAS_IMAGE_CT_COLOR(ctype)) { - case JAS_IMAGE_CT_RGB_R: - type = JP2_CDEF_TYPE_COLOR; - asoc = JP2_CDEF_RGB_R; - break; - case JAS_IMAGE_CT_RGB_G: - type = JP2_CDEF_TYPE_COLOR; - asoc = JP2_CDEF_RGB_G; - break; - case JAS_IMAGE_CT_RGB_B: - type = JP2_CDEF_TYPE_COLOR; - asoc = JP2_CDEF_RGB_B; - break; - } - break; - case JAS_CLRSPC_FAM_YCBCR: - switch (JAS_IMAGE_CT_COLOR(ctype)) { - case JAS_IMAGE_CT_YCBCR_Y: - type = JP2_CDEF_TYPE_COLOR; - asoc = JP2_CDEF_YCBCR_Y; - break; - case JAS_IMAGE_CT_YCBCR_CB: - type = JP2_CDEF_TYPE_COLOR; - asoc = JP2_CDEF_YCBCR_CB; - break; - case JAS_IMAGE_CT_YCBCR_CR: - type = JP2_CDEF_TYPE_COLOR; - asoc = JP2_CDEF_YCBCR_CR; - break; - } - break; - case JAS_CLRSPC_FAM_GRAY: - type = JP2_CDEF_TYPE_COLOR; - asoc = JP2_CDEF_GRAY_Y; - break; - } - -done: - return (type << 16) | asoc; -} - -static int clrspctojp2(jas_clrspc_t clrspc) -{ - switch (clrspc) { - case JAS_CLRSPC_SRGB: - return JP2_COLR_SRGB; - case JAS_CLRSPC_SYCBCR: - return JP2_COLR_SYCC; - case JAS_CLRSPC_SGRAY: - return JP2_COLR_SGRAY; - default: - abort(); - break; - } -} diff --git a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jpc/jpc_cs.c b/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jpc/jpc_cs.c index 2e109a742c..89e4bc3d2d 100644 --- a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jpc/jpc_cs.c +++ b/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jpc/jpc_cs.c @@ -989,8 +989,11 @@ static int jpc_qcx_getcompparms(jpc_qcxcp_t *compparms, jpc_cstate_t *cstate, compparms->numstepsizes = (len - n) / 2; break; } - if (compparms->numstepsizes > 0) { - compparms->stepsizes = jas_malloc(compparms->numstepsizes * + if (compparms->numstepsizes > 3 * JPC_MAXRLVLS + 1) { + jpc_qcx_destroycompparms(compparms); + return -1; + } else if (compparms->numstepsizes > 0) { + compparms->stepsizes = jas_alloc2(compparms->numstepsizes, sizeof(uint_fast16_t)); assert(compparms->stepsizes); for (i = 0; i < compparms->numstepsizes; ++i) { diff --git a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jpc/jpc_dec.c b/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jpc/jpc_dec.c index 6808d60a47..d44e3019be 100644 --- a/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jpc/jpc_dec.c +++ b/nativeLib/rary.cots.jasper/jasper-1.900.1/src/libjasper/jpc/jpc_dec.c @@ -496,7 +496,7 @@ static int jpc_dec_process_sot(jpc_dec_t *dec, jpc_ms_t *ms) dec->curtileendoff = 0; } - if (JAS_CAST(int, sot->tileno) > dec->numtiles) { + if (JAS_CAST(int, sot->tileno) >= dec->numtiles) { jas_eprintf("invalid tile number in SOT marker segment\n"); return -1; } @@ -1076,12 +1076,12 @@ static int jpc_dec_tiledecode(jpc_dec_t *dec, jpc_dec_tile_t *tile) /* Apply an inverse intercomponent transform if necessary. */ switch (tile->cp->mctid) { case JPC_MCT_RCT: - assert(dec->numcomps == 3); + assert(dec->numcomps >= 3); jpc_irct(tile->tcomps[0].data, tile->tcomps[1].data, tile->tcomps[2].data); break; case JPC_MCT_ICT: - assert(dec->numcomps == 3); + assert(dec->numcomps >= 3); jpc_iict(tile->tcomps[0].data, tile->tcomps[1].data, tile->tcomps[2].data); break; @@ -1211,7 +1211,7 @@ static int jpc_dec_process_siz(jpc_dec_t *dec, jpc_ms_t *ms) dec->numhtiles = JPC_CEILDIV(dec->xend - dec->tilexoff, dec->tilewidth); dec->numvtiles = JPC_CEILDIV(dec->yend - dec->tileyoff, dec->tileheight); dec->numtiles = dec->numhtiles * dec->numvtiles; - if (!(dec->tiles = jas_alloc2(dec->numtiles, sizeof(jpc_dec_tile_t)))) { + if (!(dec->tiles = jas_calloc(dec->numtiles, sizeof(jpc_dec_tile_t)))) { return -1; } @@ -1235,7 +1235,7 @@ static int jpc_dec_process_siz(jpc_dec_t *dec, jpc_ms_t *ms) tile->pkthdrstreampos = 0; tile->pptstab = 0; tile->cp = 0; - if (!(tile->tcomps = jas_alloc2(dec->numcomps, + if (!(tile->tcomps = jas_calloc(dec->numcomps, sizeof(jpc_dec_tcomp_t)))) { return -1; } @@ -1287,7 +1287,7 @@ static int jpc_dec_process_coc(jpc_dec_t *dec, jpc_ms_t *ms) jpc_coc_t *coc = &ms->parms.coc; jpc_dec_tile_t *tile; - if (JAS_CAST(int, coc->compno) > dec->numcomps) { + if (JAS_CAST(int, coc->compno) >= dec->numcomps) { jas_eprintf("invalid component number in COC marker segment\n"); return -1; } @@ -1313,7 +1313,7 @@ static int jpc_dec_process_rgn(jpc_dec_t *dec, jpc_ms_t *ms) jpc_rgn_t *rgn = &ms->parms.rgn; jpc_dec_tile_t *tile; - if (JAS_CAST(int, rgn->compno) > dec->numcomps) { + if (JAS_CAST(int, rgn->compno) >= dec->numcomps) { jas_eprintf("invalid component number in RGN marker segment\n"); return -1; } @@ -1362,7 +1362,7 @@ static int jpc_dec_process_qcc(jpc_dec_t *dec, jpc_ms_t *ms) jpc_qcc_t *qcc = &ms->parms.qcc; jpc_dec_tile_t *tile; - if (JAS_CAST(int, qcc->compno) > dec->numcomps) { + if (JAS_CAST(int, qcc->compno) >= dec->numcomps) { jas_eprintf("invalid component number in QCC marker segment\n"); return -1; }