]> git.sesse.net Git - vlc/blobdiff - modules/demux/mp4/mp4.c
*mp4: fixed segfault when it fails to start a decoder and has specific
[vlc] / modules / demux / mp4 / mp4.c
index 3ec85e118ef928a9ac2344159e8f5147dbb5a4d4..f793b1e99c746e2737c1e1a93b0f1b5e07936f45 100644 (file)
@@ -2,7 +2,7 @@
  * mp4.c : MP4 file input module for vlc
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: mp4.c,v 1.10 2002/12/14 18:57:34 fenrir Exp $
+ * $Id: mp4.c,v 1.14 2003/01/25 17:21:40 fenrir Exp $
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -190,8 +190,8 @@ static int MP4Init( vlc_object_t * p_this )
         msg_Err( p_input, 
                  "MP4 plugin discarded (%d moov box)",
                  MP4_BoxCount( &p_demux->box_root, "/moov" ) );
-        MP4End( p_input );
-        return( -1 );
+//        MP4End( p_input );
+//        return( -1 );
     }
 
     if( !(p_mvhd = MP4_BoxGet( &p_demux->box_root, "/moov/mvhd" ) ) )
@@ -441,6 +441,7 @@ static void __MP4End ( vlc_object_t * p_this )
                FREE(p_demux->track[i_track].chunk[i_chunk].p_sample_delta_dts );
             }
         }
+        FREE( p_demux->track[i_track].chunk );
 
         if( !p_demux->track[i_track].i_sample_size )
         {
@@ -448,6 +449,8 @@ static void __MP4End ( vlc_object_t * p_this )
         }
     }
     FREE( p_demux->track );
+
+    FREE( p_input->p_demux_data );
 #undef FREE
 }
 
@@ -1057,7 +1060,8 @@ static void MP4_StartDecoder( input_thread_t *p_input,
         case( VIDEO_ES ):    
             /* now create a bitmapinfoheader_t for decoder and 
                add information found in p_esds */
-            p_init = malloc( sizeof( BITMAPINFOHEADER ) + i_decoder_specific_info_len );
+            /* XXX XXX + 16 are for avoid segfault when ffmpeg access beyong the data */
+            p_init = malloc( sizeof( BITMAPINFOHEADER ) + i_decoder_specific_info_len + 16 );
             p_bih = (BITMAPINFOHEADER*)p_init;
 
             p_bih->biSize     = sizeof( BITMAPINFOHEADER ) + i_decoder_specific_info_len;
@@ -1117,7 +1121,7 @@ static void MP4_StartDecoder( input_thread_t *p_input,
             break;
 
         case( AUDIO_ES ):
-            p_init = malloc( sizeof( WAVEFORMATEX ) + i_decoder_specific_info_len);
+            p_init = malloc( sizeof( WAVEFORMATEX ) + i_decoder_specific_info_len + 16 );
             p_wf = (WAVEFORMATEX*)p_init;
 
             p_wf->wFormatTag = 0;
@@ -1143,12 +1147,23 @@ static void MP4_StartDecoder( input_thread_t *p_input,
             p_init = NULL;
             break;
     }
-
-    p_demux_track->p_es->p_demux_data = (es_sys_t *)p_init;
+    if( p_demux_track->i_cat == AUDIO_ES )
+    {
+        p_demux_track->p_es->p_waveformatex = (void*)p_init;
+    }
+    else if( p_demux_track->i_cat == VIDEO_ES )
+    {
+        p_demux_track->p_es->p_bitmapinfoheader = (void*)p_init;
+    }
     vlc_mutex_lock( &p_input->stream.stream_lock );
     input_SelectES( p_input, p_demux_track->p_es );
     vlc_mutex_unlock( &p_input->stream.stream_lock );
 
+    if( !p_demux_track->p_es->p_decoder_fifo )
+    {
+        msg_Warn( p_input, "cannot start decoder" );
+        return;
+    }
     if( p_pes_init != NULL )
     {
         input_DecodePES( p_demux_track->p_es->p_decoder_fifo, p_pes_init );