[trunk] Remove deprecated functions (not called anywhere in the code base).
[openjpeg.git] / src / lib / openjp2 / jp2.c
index f8eb907d631988ba89d185e21732edf82a9a619a..92a3726aa8ded0e455ef4f67ac92549c41969a11 100644 (file)
@@ -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)
                {
@@ -1294,6 +1301,8 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
                    p_image->color_space = OPJ_CLRSPC_GRAY;
            else if (jp2->enumcs == 18)
                    p_image->color_space = OPJ_CLRSPC_SYCC;
+            else if (jp2->enumcs == 24)
+                    p_image->color_space = OPJ_CLRSPC_EYCC;
            else
                    p_image->color_space = OPJ_CLRSPC_UNKNOWN;
 
@@ -1817,6 +1826,12 @@ OPJ_BOOL opj_jp2_read_header_procedure(  opj_jp2_t *jp2,
                        opj_free(l_current_data);
                        return OPJ_FALSE;
                }
+               /* testcase 1851.pdf.SIGSEGV.ce9.948 */
+               else if (box.length < l_nb_bytes_read) {
+                       opj_event_msg(p_manager, EVT_ERROR, "invalid box size %d (%x)\n", box.length, box.type);
+                       opj_free(l_current_data);
+                       return OPJ_FALSE;
+               }
 
                l_current_handler = opj_jp2_find_handler(box.type);
                l_current_data_size = box.length - l_nb_bytes_read;