[vlc-devel] [PATCH] mkv: fixed faulty logic in matroska_Segment_c::ParseInfo

Filip Roséen filip at videolabs.io
Mon Mar 14 15:06:25 CET 2016


Steve "robux4" Lhomme noticed an error in the code-refactoring that
would create a new chapter_translation_c for every subelement found,
even though the found subelements should belong to the same
chapter_translation_c.

This patch fixes that by introducing a nested dispatch-handler for the
EbmlTypes belonging to a KaxChapterTranslate.
---
 modules/demux/mkv/matroska_segment_parse.cpp | 51 ++++++++++++++--------------
 1 file changed, 26 insertions(+), 25 deletions(-)

diff --git a/modules/demux/mkv/matroska_segment_parse.cpp b/modules/demux/mkv/matroska_segment_parse.cpp
index 16e93d6..71dac0d 100644
--- a/modules/demux/mkv/matroska_segment_parse.cpp
+++ b/modules/demux/mkv/matroska_segment_parse.cpp
@@ -810,45 +810,46 @@ void matroska_segment_c::ParseInfo( KaxInfo *info )
         }
         E_CASE( KaxChapterTranslate, trans )
         {
-            KaxChapterTranslate *p_trans = &trans;
+            MKV_SWITCH_CREATE( EbmlTypeDispatcher, TranslationHandler, chapter_translation_c* )
+            {
+                MKV_SWITCH_INIT();
+
+                E_CASE( KaxChapterTranslateEditionUID, uid )
+                {
+                    vars->editions.push_back( static_cast<uint64>( uid ) );
+                }
+                E_CASE( KaxChapterTranslateCodec, codec_id )
+                {
+                    vars->codec_id = static_cast<uint32>( codec_id );
+                }
+                E_CASE( KaxChapterTranslateID, translated_id )
+                {
+                    vars->p_translated = new KaxChapterTranslateID( translated_id );
+                }
+            };
             try
             {
-                if( unlikely( p_trans->IsFiniteSize() && p_trans->GetSize() >= SIZE_MAX ) )
+                if( unlikely( trans.IsFiniteSize() && trans.GetSize() >= SIZE_MAX ) )
                 {
                     msg_Err( vars.p_demuxer, "Chapter translate too big, aborting" );
                     return;
                 }
 
-                p_trans->Read( vars.obj->es, EBML_CONTEXT(p_trans), vars.i_upper_level, vars.el, true );
+                trans.Read( vars.obj->es, EBML_CONTEXT(&trans), vars.i_upper_level, vars.el, true );
+
+                chapter_translation_c *p_translate = new chapter_translation_c();
 
-                dispatcher.iterate( p_trans->begin(), p_trans->end(), Payload( vars ) );
+                TranslationHandler::Dispatcher().iterate(
+                    trans.begin(), trans.end(), TranslationHandler::Payload( p_translate ) 
+                );
+
+                vars.obj->translations.push_back( p_translate );
             }
             catch(...)
             {
                 msg_Err( vars.p_demuxer, "Error while reading Chapter Tranlate");
             }
         }
-        E_CASE( KaxChapterTranslateEditionUID, uid )
-        {
-            chapter_translation_c *p_translate = new chapter_translation_c();
-            p_translate->editions.push_back( static_cast<uint64>( uid ) );
-
-            vars.obj->translations.push_back( p_translate );
-        }
-        E_CASE( KaxChapterTranslateCodec, codec_id )
-        {
-            chapter_translation_c *p_translate = new chapter_translation_c();
-            p_translate->codec_id = static_cast<uint32>( codec_id );
-
-            vars.obj->translations.push_back( p_translate );
-        }
-        E_CASE( KaxChapterTranslateID, translated_id )
-        {
-            chapter_translation_c *p_translate = new chapter_translation_c();
-            p_translate->p_translated = new KaxChapterTranslateID( translated_id );
-
-            vars.obj->translations.push_back( p_translate );
-        }
         E_CASE( EbmlVoid, )
         {
             VLC_UNUSED( vars );
-- 
2.7.3



More information about the vlc-devel mailing list