From a3472624683709544fa98c33ed8a3137b4436959 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 27 Feb 2014 17:21:00 +0000 Subject: [PATCH] [trunk] Import patch from issue 218. No dataset to check, so blindly applied it. Fixes issue 218 --- src/lib/openjp2/jp2.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 544ce91b..d59ec434 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -823,6 +823,7 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, return OPJ_TRUE; } +// file9.jp2 void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color) { opj_image_comp_t *old_comps, *new_comps; @@ -1076,7 +1077,8 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color) for(i = 0; i < n; ++i) { /* WATCH: acn = asoc - 1 ! */ - if((asoc = info[i].asoc) == 0) + asoc = info[i].asoc; + if(asoc == 0 || asoc == 65535) { if (i < image->numcomps) image->comps[i].alpha = info[i].typ; @@ -1085,6 +1087,11 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color) cn = info[i].cn; acn = asoc - 1; + if( cn >= image->numcomps || acn >= image->numcomps ) + { + fprintf(stderr, "cn=%d, acn=%d, numcomps=%d\n", cn, acn, image->numcomps); + continue; + } if(cn != acn) {