[vlc-commits] Fix crash in invalid mkv files

Cheng Sun git at videolan.org
Wed Nov 23 23:49:35 CET 2011


vlc | branch: master | Cheng Sun <chengsun9 at gmail.com> | Wed Nov 23 21:39:12 2011 +0000| [73160f1a9bd3b3fa666abdd0c65ad7a083ea3b93] | committer: Jean-Baptiste Kempf

Fix crash in invalid mkv files

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 at dinauz.org>
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=73160f1a9bd3b3fa666abdd0c65ad7a083ea3b93
---

 modules/demux/mkv/demux.cpp |    8 +++++++-
 modules/demux/mkv/demux.hpp |    2 +-
 modules/demux/mkv/mkv.cpp   |    5 ++---
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/modules/demux/mkv/demux.cpp b/modules/demux/mkv/demux.cpp
index 6ebcaef..a8c8aa4 100644
--- a/modules/demux/mkv/demux.cpp
+++ b/modules/demux/mkv/demux.cpp
@@ -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;
 }
diff --git a/modules/demux/mkv/demux.hpp b/modules/demux/mkv/demux.hpp
index 0497089..db72f5d 100644
--- a/modules/demux/mkv/demux.hpp
+++ b/modules/demux/mkv/demux.hpp
@@ -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 );
diff --git a/modules/demux/mkv/mkv.cpp b/modules/demux/mkv/mkv.cpp
index b056b8b..16d6b7d 100644
--- a/modules/demux/mkv/mkv.cpp
+++ b/modules/demux/mkv/mkv.cpp
@@ -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;



More information about the vlc-commits mailing list