]> git.sesse.net Git - vlc/commitdiff
Fix crash in invalid mkv files
authorCheng Sun <chengsun9@gmail.com>
Wed, 23 Nov 2011 21:39:12 +0000 (21:39 +0000)
committerJean-Baptiste Kempf <jb@videolan.org>
Wed, 23 Nov 2011 22:49:29 +0000 (23:49 +0100)
VirtualFromSegments can crash if the std::vector passed in is empty, which
can happen in corrupted files. This is just a simple check for this case,
making it fail elegantly rather than crashing

OK-ed-by: Denis Charmet <typx@dinauz.org>
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/demux/mkv/demux.cpp
modules/demux/mkv/demux.hpp
modules/demux/mkv/mkv.cpp

index 6ebcaef65184cc4661ca6e0bffcefcf88b4ab639..a8c8aa4167e607065d06408e8618547b97b5f7ac 100644 (file)
@@ -634,12 +634,14 @@ void demux_sys_t::PreloadFamily( const matroska_segment_c & of_segment )
 }
 
 // preload all the linked segments for all preloaded segments
-void demux_sys_t::PreloadLinked()
+bool demux_sys_t::PreloadLinked()
 {
     size_t i, j;
     virtual_segment_c *p_seg;
 
     p_current_segment = VirtualFromSegments( &opened_segments );
+    if ( !p_current_segment )
+        return false;
 
     used_segments.push_back( p_current_segment );
 
@@ -679,10 +681,14 @@ void demux_sys_t::PreloadLinked()
     }
 
     // TODO decide which segment should be first used (VMG for DVD)
+
+    return true;
 }
 
 virtual_segment_c *demux_sys_t::VirtualFromSegments( std::vector<matroska_segment_c*> *p_segments ) const
 {
+    if ( p_segments->empty() )
+        return NULL;
     virtual_segment_c *p_result = new virtual_segment_c( p_segments );
     return p_result;
 }
index 0497089dc298003187f1d6714521e37120ea2017..db72f5d9e084185d1e3edd7f86e6690c80e16291 100644 (file)
@@ -379,7 +379,7 @@ public:
     virtual_chapter_c *FindChapter( int64_t i_find_uid, virtual_segment_c * & p_segment_found );
 
     void PreloadFamily( const matroska_segment_c & of_segment );
-    void PreloadLinked();
+    bool PreloadLinked();
     bool PreparePlayback( virtual_segment_c *p_new_segment );
     matroska_stream_c *AnalyseAllSegmentsFound( demux_t *p_demux, EbmlStream *p_estream, bool b_initial = false );
     void JumpTo( virtual_segment_c & p_segment, virtual_chapter_c * p_chapter );
index b056b8b0d226527b0991f78ec77f66d3cb76274b..16d6b7d4180e4229e72a776414c49c68fdd7c387 100644 (file)
@@ -234,9 +234,8 @@ static int Open( vlc_object_t * p_this )
         p_sys->PreloadFamily( *p_segment );
     }
 
-    p_sys->PreloadLinked();
-
-    if ( !p_sys->PreparePlayback( NULL ) )
+    if ( !p_sys->PreloadLinked() ||
+         !p_sys->PreparePlayback( NULL ) )
     {
         msg_Err( p_demux, "cannot use the segment" );
         goto error;