[vlc-commits] demux:mkv: don't read further than our parent or its parent

Steve Lhomme git at videolan.org
Tue Nov 14 10:55:06 CET 2017


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Mon Nov 13 18:08:45 2017 +0100| [afdbb2799def3351e28ecb82a9bce630d9d050dd] | committer: Jean-Baptiste Kempf

demux:mkv: don't read further than our parent or its parent

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

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

 modules/demux/mkv/Ebml_parser.cpp | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/modules/demux/mkv/Ebml_parser.cpp b/modules/demux/mkv/Ebml_parser.cpp
index 330edd4c7c..5f663c6a45 100644
--- a/modules/demux/mkv/Ebml_parser.cpp
+++ b/modules/demux/mkv/Ebml_parser.cpp
@@ -158,6 +158,27 @@ EbmlElement *EbmlParser::Get( int n_call )
     if( p_prev )
         p_prev->SkipData( *m_es, EBML_CONTEXT(p_prev) );
 
+    uint64_t i_max_read;
+    if (mi_level == 0)
+        i_max_read = UINT64_MAX;
+    else if (!m_el[mi_level-1]->IsFiniteSize())
+        i_max_read = UINT64_MAX;
+    else if (!p_prev)
+        i_max_read = m_el[mi_level-1]->GetSize();
+    else {
+        size_t size_lvl = mi_level;
+        while ( size_lvl && m_el[size_lvl-1]->IsFiniteSize() &&
+                m_el[size_lvl-1]->GetEndPosition() == m_el[size_lvl]->GetEndPosition() )
+            size_lvl--;
+        if (size_lvl == 0 || !m_el[size_lvl-1]->IsFiniteSize() )
+            i_max_read = UINT64_MAX;
+        else {
+            uint64 top = m_el[size_lvl-1]->GetEndPosition();
+            uint64 bom = m_el[mi_level]->GetEndPosition();
+            i_max_read = top - bom;
+        }
+    }
+
     // If the parent is a segment, use the segment context when creating children
     // (to prolong their lifetime), otherwise just continue as normal
     EbmlSemanticContext e_context =
@@ -167,7 +188,7 @@ EbmlElement *EbmlParser::Get( int n_call )
 
     /* Ignore unknown level 0 or 1 elements */
     m_el[mi_level] = m_es->FindNextElement( e_context,
-                                            i_ulev, UINT64_MAX,
+                                            i_ulev, i_max_read,
                                             (  mb_dummy | (mi_level > 1) ), 1 );
     if( i_ulev > 0 )
     {



More information about the vlc-commits mailing list