[vlc-commits] Handle mkv file with random data appended

Denis Charmet git at videolan.org
Wed Sep 21 02:14:56 CEST 2011


vlc | branch: master | Denis Charmet <typx at dinauz.org> | Sun Sep 18 23:53:26 2011 +0200| [ad2446286fba9f93012312d72a89134674bf7b7e] | committer: Jean-Baptiste Kempf

Handle mkv file with random data appended

EbmlElement doesn't detect EOF so we don't try to look for more than the file size.
Close #5287

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/demux/mkv/Ebml_parser.cpp        |    8 +++++---
 modules/demux/mkv/stream_io_callback.cpp |   15 +++++++++++++++
 modules/demux/mkv/stream_io_callback.hpp |    1 +
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/modules/demux/mkv/Ebml_parser.cpp b/modules/demux/mkv/Ebml_parser.cpp
index 8abe76c..cd81d8d 100644
--- a/modules/demux/mkv/Ebml_parser.cpp
+++ b/modules/demux/mkv/Ebml_parser.cpp
@@ -24,6 +24,7 @@
  *****************************************************************************/
 
 #include "Ebml_parser.hpp"
+#include "stream_io_callback.hpp"
 
 /*****************************************************************************
  * Ebml Stream parser
@@ -77,7 +78,7 @@ EbmlElement* EbmlParser::UnGet( uint64 i_block_pos, uint64 i_cluster_pos )
     }
     m_got = NULL;
     mb_keep = false;
-    if ( m_el[1]->GetElementPosition() == i_cluster_pos )
+    if ( m_el[1] && m_el[1]->GetElementPosition() == i_cluster_pos )
     {
         m_es->I_O().setFilePointer( i_block_pos, seek_beginning );
         return (EbmlMaster*) m_el[1];
@@ -161,8 +162,9 @@ EbmlElement *EbmlParser::Get( void )
         }
         mb_keep = false;
     }
-
-    m_el[mi_level] = m_es->FindNextElement( EBML_CONTEXT(m_el[mi_level - 1]), i_ulev, 0xFFFFFFFFL, mb_dummy != 0, 1 );
+    vlc_stream_io_callback & io_stream = (vlc_stream_io_callback &) m_es->I_O();
+    uint64 i_size = io_stream.toRead();
+    m_el[mi_level] = m_es->FindNextElement( EBML_CONTEXT(m_el[mi_level - 1]), i_ulev, i_size, mb_dummy != 0, 1 );
 //    mi_remain_size[mi_level] = m_el[mi_level]->GetSize();
     if( i_ulev > 0 )
     {
diff --git a/modules/demux/mkv/stream_io_callback.cpp b/modules/demux/mkv/stream_io_callback.cpp
index ae3cd8f..2fff1ef 100644
--- a/modules/demux/mkv/stream_io_callback.cpp
+++ b/modules/demux/mkv/stream_io_callback.cpp
@@ -87,3 +87,18 @@ size_t vlc_stream_io_callback::write(const void *, size_t )
     return 0;
 }
 
+uint64 vlc_stream_io_callback::toRead( void )
+{
+    uint64_t i_size;
+
+    if( s == NULL)
+        return 0;
+
+    stream_Control( s, STREAM_GET_SIZE, &i_size );
+
+    if( i_size == 0 )
+        return 0xFFFFFFFFL;
+
+    return (uint64) i_size - stream_Tell( s );
+}
+
diff --git a/modules/demux/mkv/stream_io_callback.hpp b/modules/demux/mkv/stream_io_callback.hpp
index c67faeb..11566da 100644
--- a/modules/demux/mkv/stream_io_callback.hpp
+++ b/modules/demux/mkv/stream_io_callback.hpp
@@ -47,5 +47,6 @@ class vlc_stream_io_callback: public IOCallback
     virtual size_t   write           ( const void *p_buffer, size_t i_size);
     virtual uint64   getFilePointer  ( void );
     virtual void     close           ( void ) { return; }
+    uint64           toRead          ( void );
 };
 



More information about the vlc-commits mailing list