Fix undefined size jp2 box handling
[openjpeg.git] / src / lib / openjp2 / openjpeg.c
index c53604d3592659641992b7793a9ede54cf6b7a5a..5114cc1086d368ec4714c85aabd29e29e39ee8cc 100644 (file)
@@ -132,7 +132,7 @@ static OPJ_BOOL opj_seek_from_file (OPJ_OFF_T p_nb_bytes, FILE * p_user_data)
 #ifdef _WIN32
 #ifndef OPJ_STATIC
 BOOL APIENTRY
-DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
+DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
 
        OPJ_ARG_NOT_USED(lpReserved);
        OPJ_ARG_NOT_USED(hModule);
@@ -169,7 +169,6 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
        if (!l_codec){
                return 00;
        }
-       memset(l_codec, 0, sizeof(opj_codec_private_t));
 
        l_codec->is_decompressor = 1;
 
@@ -525,14 +524,12 @@ OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec,
        opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
 
        if ( !l_codec ){
-               fprintf(stderr, "[ERROR] Input parameters of the setup_decoder function are incorrect.\n");
                return OPJ_FALSE;
        }
 
-       l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor(l_codec->m_codec, 
+       return l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor(l_codec->m_codec,
                                                                                                                                                        res_factor,
                                                                                                                                                        &(l_codec->m_event_mgr) );
-       return OPJ_TRUE;
 }
 
 /* ---------------------------------------------------------------------- */
@@ -546,7 +543,6 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
        if (!l_codec) {
                return 00;
        }
-       memset(l_codec, 0, sizeof(opj_codec_private_t));
        
        l_codec->is_decompressor = 0;
 
@@ -574,7 +570,7 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
 
                        l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_j2k_destroy;
 
-                       l_codec->m_codec_data.m_compression.opj_setup_encoder = (void (*) (     void *,
+                       l_codec->m_codec_data.m_compression.opj_setup_encoder = (OPJ_BOOL (*) ( void *,
                                                                                                                                                                opj_cparameters_t *,
                                                                                                                                                                struct opj_image *,
                                                                                                                                                                struct opj_event_mgr * )) opj_j2k_setup_encoder;
@@ -611,7 +607,7 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
 
                        l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_jp2_destroy;
 
-                       l_codec->m_codec_data.m_compression.opj_setup_encoder = (void (*) (     void *,
+                       l_codec->m_codec_data.m_compression.opj_setup_encoder = (OPJ_BOOL (*) ( void *,
                                                                                                                                                                opj_cparameters_t *,
                                                                                                                                                                struct opj_image *,
                                                                                                                                                                struct opj_event_mgr * )) opj_jp2_setup_encoder;
@@ -702,11 +698,10 @@ OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec,
                opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
 
                if (! l_codec->is_decompressor) {
-                       l_codec->m_codec_data.m_compression.opj_setup_encoder(  l_codec->m_codec,
+                       return l_codec->m_codec_data.m_compression.opj_setup_encoder(   l_codec->m_codec,
                                                                                                                                        parameters,
                                                                                                                                        p_image,
                                                                                                                                        &(l_codec->m_event_mgr) );
-                       return OPJ_TRUE;
                }
        }
 
@@ -871,7 +866,8 @@ void OPJ_CALLCONV opj_dump_codec(   opj_codec_t *p_codec,
                return;
        }
 
-       fprintf(stderr, "[ERROR] Input parameter of the dump_codec function are incorrect.\n");
+       /* TODO return error */
+       /* fprintf(stderr, "[ERROR] Input parameter of the dump_codec function are incorrect.\n"); */
        return;
 }
 
@@ -921,12 +917,12 @@ void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index)
        }
 }
 
-opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream)
+opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (const char *fname, OPJ_BOOL p_is_read_stream)
 {
-    return opj_stream_create_file_stream_v3(fname, OPJ_J2K_STREAM_CHUNK_SIZE, p_is_read_stream);
+    return opj_stream_create_file_stream(fname, OPJ_J2K_STREAM_CHUNK_SIZE, p_is_read_stream);
 }
 
-opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 (
+opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (
         const char *fname, 
                OPJ_SIZE_T p_size, 
         OPJ_BOOL p_is_read_stream)
@@ -953,7 +949,7 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 (
         return NULL;
     }
 
-    opj_stream_set_user_data_v3(l_stream, p_file, (opj_stream_free_user_data_fn) fclose);
+    opj_stream_set_user_data(l_stream, p_file, (opj_stream_free_user_data_fn) fclose);
     opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file));
     opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file);
     opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file);