[trunk] verify channel definitions is complete when cdef is present (fixes issue 397)
This commit is contained in:
parent
efb70af001
commit
0a3f234df7
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue