summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorAntonin Descampe <antonin@gmail.com>2014-10-21 12:54:08 +0000
committerAntonin Descampe <antonin@gmail.com>2014-10-21 12:54:08 +0000
commit0a3f234df7b95ca3ac7e3d3a3019d24cb4cf5a83 (patch)
treed25749b672834568f6fe6cc091924fdb3c1eaf1e /src/lib
parentefb70af001401c2cf3e9e60e308225ceb95ae9b6 (diff)
[trunk] verify channel definitions is complete when cdef is present (fixes issue 397)
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/openjp2/jp2.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c
index b6ecba66..78a15026 100644
--- a/src/lib/openjp2/jp2.c
+++ b/src/lib/openjp2/jp2.c
@@ -764,6 +764,12 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
if (color->jp2_cdef) {
opj_jp2_cdef_info_t *info = color->jp2_cdef->info;
OPJ_UINT16 n = color->jp2_cdef->n;
+ OPJ_UINT32 nr_channels = image->numcomps; /* FIXME image->numcomps == jp2->numcomps before color is applied ??? */
+
+ /* cdef applies to cmap channels if any */
+ if (color->jp2_pclr && color->jp2_pclr->cmap) {
+ nr_channels = (OPJ_UINT32)color->jp2_pclr->nr_channels;
+ }
for (i = 0; i < n; i++) {
if (info[i].cn >= image->numcomps) {
@@ -775,6 +781,22 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
return OPJ_FALSE;
}
}
+
+ /* issue 397 */
+ /* ISO 15444-1 states that if cdef is present, it shall contain a complete list of channel definitions. */
+ while (nr_channels > 0)
+ {
+ for(i = 0; i < n; ++i) {
+ if ((OPJ_UINT32)info[i].cn == (nr_channels - 1U)) {
+ break;
+ }
+ }
+ if (i == n) {
+ opj_event_msg(p_manager, EVT_ERROR, "Incomplete channel definitions.\n");
+ return OPJ_FALSE;
+ }
+ --nr_channels;
+ }
}
/* testcases 451.pdf.SIGSEGV.f4c.3723, 451.pdf.SIGSEGV.5b5.3723 and