]> granicus.if.org Git - openjpeg/commitdiff
[trunk] remove all api with invalid FILE* parameters which could leads to issues...
authorMathieu Malaterre <mathieu.malaterre@gmail.com>
Mon, 3 Mar 2014 11:36:31 +0000 (11:36 +0000)
committerMathieu Malaterre <mathieu.malaterre@gmail.com>
Mon, 3 Mar 2014 11:36:31 +0000 (11:36 +0000)
Fixes issue 198

src/lib/openjp2/openjpeg.c
src/lib/openjp2/openjpeg.h
src/lib/openjpip/jp2k_decoder.c
src/lib/openjpip/jp2k_decoder.h
src/lib/openjpip/jpipstream_manager.c

index 31199b2433bebd576ce98133604b9da7d7c136b1..957143f3dba50692a1f91e89dc83a74a254511c3 100644 (file)
@@ -1029,49 +1029,11 @@ void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index)
        }
 }
 
-/* ---------------------------------------------------------------------- */
-static opj_stream_t* opj_stream_create_file_stream_impl (      FILE * p_file, 
-                                                                                                                       OPJ_SIZE_T p_size, 
-                                                                                                                       OPJ_BOOL p_is_read_stream)
-{
-       opj_stream_t* l_stream = 00;
-
-       if (! p_file) {
-               return NULL;
-       }
-
-       l_stream = opj_stream_create(p_size,p_is_read_stream);
-       if (! l_stream) {
-               return NULL;
-       }
-
-    opj_stream_set_user_data(l_stream, p_file);
-    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);
-    opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file);
-    opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file);
-    
-    return l_stream;
-}
-
-opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream)
-{
-       return opj_stream_create_file_stream_impl(p_file,OPJ_J2K_STREAM_CHUNK_SIZE,p_is_read_stream);
-}
-
 opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (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);
 }
 
-opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (     FILE * p_file, 
-                                                                                                                       OPJ_SIZE_T p_size, 
-                                                                                                                       OPJ_BOOL p_is_read_stream)
-{
-       return opj_stream_create_file_stream_impl(p_file,p_size,p_is_read_stream);
-}
-
 opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 (
         const char *fname, 
                OPJ_SIZE_T p_size, 
index 338a771dee05ac4c25951e3fd54c34950171d685..8170f7a4683fc3056d4aa96e1a9d7f741d81878e 100644 (file)
@@ -1060,14 +1060,6 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void
 */
 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length);
 
-/**
- * Helper function.
- * Sets the stream to be a file stream. The FILE must have been open previously.
- * @param p_file            the file stream to operate on
- * @param p_is_read_stream  whether the stream is a read stream (true) or not (false)
-*/
-OPJ_DEPRECATED(OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream));
-
 /**
  * Create a stream from a file identified with its filename with default parameters (helper function)
  * @param fname             the filename of the file to stream
@@ -1075,16 +1067,6 @@ OPJ_DEPRECATED(OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file
 */
 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream);
  
-/**
- * FIXME DOC
- * @param p_file            the file stream to operate on
- * @param p_buffer_size     size of the chunk used to stream
- * @param p_is_read_stream  whether the stream is a read stream (true) or not (false)
-*/
-OPJ_DEPRECATED(OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, 
-                                                                  OPJ_SIZE_T p_buffer_size,
-                                                                  OPJ_BOOL p_is_read_stream));
-
 /** Create a stream from a file identified with its filename with a specific buffer size
  * @param fname             the filename of the file to stream
  * @param p_buffer_size     size of the chunk used to stream
index 9bbfe00dbb995647682c87ea821316d128141001..a1878adc2740f5484655d6a0134c520334ec33b9 100644 (file)
@@ -43,7 +43,7 @@ static void info_callback(const char *msg, void *client_data);
 
 static Byte_t * imagetopnm(opj_image_t *image, ihdrbox_param_t **ihdrbox);
 
-Byte_t * j2k_to_pnm( FILE *fp, ihdrbox_param_t **ihdrbox)
+Byte_t * j2k_to_pnm( const char *fn, ihdrbox_param_t **ihdrbox)
 {
   Byte_t *pnmstream = NULL;
   opj_dparameters_t parameters;        /* decompression parameters */
@@ -51,13 +51,11 @@ Byte_t * j2k_to_pnm( FILE *fp, ihdrbox_param_t **ihdrbox)
   opj_codec_t *l_codec = NULL; /* handle to a decompressor */
   opj_stream_t *l_stream = NULL;
 
-
-
   /* set decoding parameters to default values */
   opj_set_default_decoder_parameters(&parameters);
 
   /* set a byte stream */
-  l_stream = opj_stream_create_default_file_stream( fp, 1);
+  l_stream = opj_stream_create_default_file_stream_v3( fn, OPJ_TRUE);
   if (!l_stream){
     fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
     return NULL;
index a53b1537b30883040e54a91d1cee9ff49bce5091..7fc8e961e4a34feeb7f5249eef8842e9383ebc9d 100644 (file)
@@ -34,6 +34,6 @@
 #include "byte_manager.h"
 #include "ihdrbox_manager.h"
 
-Byte_t * j2k_to_pnm( FILE *fp, ihdrbox_param_t **ihdrbox);
+Byte_t * j2k_to_pnm( const char *fn, ihdrbox_param_t **ihdrbox);
 
 #endif             /* !JP2K_DECODER_H_ */
index 3227af755a4292fdb9614c9785dac760c77c32b8..6649129ce7b757db398e7873e9f18f63cc83cfa4 100644 (file)
@@ -76,19 +76,34 @@ Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte
   Byte_t *pnmstream;
   Byte_t *j2kstream; /* j2k or jp2 codestream */
   Byte8_t j2klen;
+  size_t retlen;
   FILE *fp;
   const char j2kfname[] = "tmp.j2k";
 
+  fp = fopen( j2kfname, "w+b");
+  if( !fp )
+    {
+    return NULL;
+    }
   j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen); 
+  if( !j2kstream )
+    {
+    fclose(fp);
+    remove( j2kfname);
+    return NULL;
+    }
 
-  fp = fopen( j2kfname, "w+b");
-  fwrite( j2kstream, j2klen, 1, fp);
+  retlen = fwrite( j2kstream, 1, j2klen, fp);
   opj_free( j2kstream);
-  fseek( fp, 0, SEEK_SET);
+  fclose(fp);
+  if( retlen != j2klen )
+    {
+    remove( j2kfname);
+    return NULL;
+    }
 
-  pnmstream = j2k_to_pnm( fp, ihdrbox);
+  pnmstream = j2k_to_pnm( j2kfname, ihdrbox);
 
-  fclose( fp);
   remove( j2kfname);
 
   return pnmstream;