Commit 73160f1a authored by Cheng Sun's avatar Cheng Sun Committed by 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: default avatarDenis Charmet <typx@dinauz.org>
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 2bb4972e
...@@ -634,12 +634,14 @@ void demux_sys_t::PreloadFamily( const matroska_segment_c & of_segment ) ...@@ -634,12 +634,14 @@ void demux_sys_t::PreloadFamily( const matroska_segment_c & of_segment )
} }
// preload all the linked segments for all preloaded segments // preload all the linked segments for all preloaded segments
void demux_sys_t::PreloadLinked() bool demux_sys_t::PreloadLinked()
{ {
size_t i, j; size_t i, j;
virtual_segment_c *p_seg; virtual_segment_c *p_seg;
p_current_segment = VirtualFromSegments( &opened_segments ); p_current_segment = VirtualFromSegments( &opened_segments );
if ( !p_current_segment )
return false;
used_segments.push_back( p_current_segment ); used_segments.push_back( p_current_segment );
...@@ -679,10 +681,14 @@ void demux_sys_t::PreloadLinked() ...@@ -679,10 +681,14 @@ void demux_sys_t::PreloadLinked()
} }
// TODO decide which segment should be first used (VMG for DVD) // 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 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 ); virtual_segment_c *p_result = new virtual_segment_c( p_segments );
return p_result; return p_result;
} }
......
...@@ -379,7 +379,7 @@ public: ...@@ -379,7 +379,7 @@ public:
virtual_chapter_c *FindChapter( int64_t i_find_uid, virtual_segment_c * & p_segment_found ); virtual_chapter_c *FindChapter( int64_t i_find_uid, virtual_segment_c * & p_segment_found );
void PreloadFamily( const matroska_segment_c & of_segment ); void PreloadFamily( const matroska_segment_c & of_segment );
void PreloadLinked(); bool PreloadLinked();
bool PreparePlayback( virtual_segment_c *p_new_segment ); bool PreparePlayback( virtual_segment_c *p_new_segment );
matroska_stream_c *AnalyseAllSegmentsFound( demux_t *p_demux, EbmlStream *p_estream, bool b_initial = false ); 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 ); void JumpTo( virtual_segment_c & p_segment, virtual_chapter_c * p_chapter );
......
...@@ -234,9 +234,8 @@ static int Open( vlc_object_t * p_this ) ...@@ -234,9 +234,8 @@ static int Open( vlc_object_t * p_this )
p_sys->PreloadFamily( *p_segment ); p_sys->PreloadFamily( *p_segment );
} }
p_sys->PreloadLinked(); if ( !p_sys->PreloadLinked() ||
!p_sys->PreparePlayback( NULL ) )
if ( !p_sys->PreparePlayback( NULL ) )
{ {
msg_Err( p_demux, "cannot use the segment" ); msg_Err( p_demux, "cannot use the segment" );
goto error; goto error;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment