mkv: don't let zlib_decompress_extra() destroy the track it's given
authorSteve Lhomme <robUx4@videolabs.io>
Mon, 31 Jul 2017 13:02:55 +0000 (15:02 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Mon, 31 Jul 2017 13:16:55 +0000 (15:16 +0200)
It didn't clean the es_format_t that's fully filled.
Also emit an error telling we can't handle the compression.

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/demux/mkv/matroska_segment_parse.cpp
modules/demux/mkv/util.cpp
modules/demux/mkv/util.hpp

index 896d6bd..7fa5da4 100644 (file)
@@ -684,9 +684,13 @@ void matroska_segment_c::ParseTrackEntry( const KaxTrackEntry *m )
         if( track.i_compression_type == MATROSKA_COMPRESSION_ZLIB &&
             track.i_encoding_scope & MATROSKA_ENCODING_SCOPE_PRIVATE &&
             track.i_extra_data && track.p_extra_data &&
-            zlib_decompress_extra( &sys.demuxer, &track ) )
-            // zlib_decompress_extra will clean the track itself
+            zlib_decompress_extra( &sys.demuxer, track ) )
+        {
+            msg_Err(&sys.demuxer, "Couldn't handle the track %u compression", track.i_number );
+            es_format_Clean( &track.fmt );
+            free(track.p_extra_data);
             return;
+        }
 #endif
         if( TrackInit( &track ) )
         {
index 1a4f157..bef5cca 100644 (file)
@@ -30,7 +30,7 @@
  *****************************************************************************/
 
 #ifdef HAVE_ZLIB_H
-int32_t zlib_decompress_extra( demux_t * p_demux, mkv_track_t * tk )
+int32_t zlib_decompress_extra( demux_t * p_demux, mkv_track_t & tk )
 {
     int result;
     z_stream d_stream;
@@ -45,14 +45,12 @@ int32_t zlib_decompress_extra( demux_t * p_demux, mkv_track_t * tk )
     if( inflateInit( &d_stream ) != Z_OK )
     {
         msg_Err( p_demux, "Couldn't initiate inflation ignore track %u",
-                 tk->i_number );
-        free(tk->p_extra_data);
-        delete tk;
+                 tk.i_number );
         return 1;
     }
 
-    d_stream.next_in = tk->p_extra_data;
-    d_stream.avail_in = tk->i_extra_data;
+    d_stream.next_in = tk.p_extra_data;
+    d_stream.avail_in = tk.i_extra_data;
     do
     {
         n++;
@@ -60,11 +58,9 @@ int32_t zlib_decompress_extra( demux_t * p_demux, mkv_track_t * tk )
         if( alloc == NULL )
         {
             msg_Err( p_demux, "Couldn't allocate buffer to inflate data, ignore track %u",
-                      tk->i_number );
+                      tk.i_number );
             free(p_new_extra);
             inflateEnd( &d_stream );
-            free(tk->p_extra_data);
-            delete tk;
             return 1;
         }
 
@@ -77,28 +73,24 @@ int32_t zlib_decompress_extra( demux_t * p_demux, mkv_track_t * tk )
             msg_Err( p_demux, "Zlib decompression failed. Result: %d", result );
             inflateEnd( &d_stream );
             free(p_new_extra);
-            free(tk->p_extra_data);
-            delete tk;
             return 1;
         }
     }
     while ( d_stream.avail_out == 0 && d_stream.avail_in != 0  &&
             result != Z_STREAM_END );
 
-    free( tk->p_extra_data );
-    tk->i_extra_data = d_stream.total_out;
-    p_new_extra = static_cast<uint8_t *>( realloc(p_new_extra, tk->i_extra_data) );
+    free( tk.p_extra_data );
+    tk.i_extra_data = d_stream.total_out;
+    p_new_extra = static_cast<uint8_t *>( realloc(p_new_extra, tk.i_extra_data) );
     if( !p_new_extra )
     {
         msg_Err( p_demux, "Couldn't allocate buffer to inflate data, ignore track %u",
-                 tk->i_number );
+                 tk.i_number );
         inflateEnd( &d_stream );
-        free(p_new_extra);
-        delete tk;
         return 1;
     }
 
-    tk->p_extra_data = p_new_extra;
+    tk.p_extra_data = p_new_extra;
 
     inflateEnd( &d_stream );
     return 0;
index 5867d1d..7bee364 100644 (file)
@@ -26,7 +26,7 @@
 #include "mkv.hpp"
 
 #ifdef HAVE_ZLIB_H
-int32_t zlib_decompress_extra( demux_t * p_demux, mkv_track_t * tk );
+int32_t zlib_decompress_extra( demux_t * p_demux, mkv_track_t & tk );
 block_t *block_zlib_decompress( vlc_object_t *p_this, block_t *p_in_block );
 #endif