[vlc-commits] demux: ttml: fix xml parsing

Francois Cartegnie git at videolan.org
Fri Oct 9 21:04:17 CEST 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Oct  9 20:37:31 2015 +0200| [9ea1737f673c8117b663238a0870dd89d305c0df] | committer: Francois Cartegnie

demux: ttml: fix xml parsing

Restores and fixes 7ce48b0d

This reverts commit 99ef553614db40ea70941f14cadad629ef905e39.
This reverts commit df5bb189902a78c9fff16e93d2ab094c3628fdf2.
This reverts commit 9abec5a24c3235aef4ff1fed1ae1a97f104930fa.

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

 modules/demux/playlist/wpl.c |   24 ++++++++++++++++++------
 modules/demux/ttml.c         |   37 ++++++++++++++++++++++++++++---------
 2 files changed, 46 insertions(+), 15 deletions(-)

diff --git a/modules/demux/playlist/wpl.c b/modules/demux/playlist/wpl.c
index 8e83434..52da7a0 100644
--- a/modules/demux/playlist/wpl.c
+++ b/modules/demux/playlist/wpl.c
@@ -27,7 +27,6 @@
 #include <vlc_common.h>
 #include <vlc_demux.h>
 #include <vlc_xml.h>
-#include <vlc_fixups.h>
 
 #include "playlist.h"
 
@@ -179,18 +178,27 @@ int Import_WPL( vlc_object_t* p_this )
     DEMUX_INIT_COMMON();
 
     demux_sys_t* p_sys = p_demux->p_sys;
-
     uint8_t *p_peek;
-    ssize_t i_peek = stream_Peek( p_demux->s, (const uint8_t **) &p_peek, 128 );
-    if( i_peek < 32 || memcmp( p_peek, "<?wpl", 5 ) ||
-        !strnstr( (const char *) p_peek, "<smil>", i_peek ) )
+    ssize_t i_peek = stream_Peek( p_demux->s, (const uint8_t **) &p_peek, 2048 );
+    if( unlikely( i_peek <= 0 ) )
+    {
+        Close_WPL( p_this );
+        return VLC_EGENERIC;
+    }
+
+    stream_t *p_probestream = stream_MemoryNew( p_demux->s, p_peek, i_peek, true );
+    if( unlikely( !p_probestream ) )
+    {
+        Close_WPL( p_this );
         return VLC_EGENERIC;
+    }
 
-    p_sys->p_reader = xml_ReaderCreate( p_this, p_demux->s );
+    p_sys->p_reader = xml_ReaderCreate( p_this, p_probestream );
     if ( !p_sys->p_reader )
     {
         msg_Err( p_demux, "Failed to create an XML reader" );
         Close_WPL( p_this );
+        stream_Delete( p_probestream );
         return VLC_EGENERIC;
     }
 
@@ -200,9 +208,13 @@ int Import_WPL( vlc_object_t* p_this )
     {
         msg_Err( p_demux, "Invalid WPL playlist. Root element should have been <smil>" );
         Close_WPL( p_this );
+        stream_Delete( p_probestream );
         return VLC_EGENERIC;
     }
 
+    p_sys->p_reader = xml_ReaderReset( p_sys->p_reader, p_demux->s );
+    stream_Delete( p_probestream );
+
     msg_Dbg( p_demux, "Found valid WPL playlist" );
 
     return VLC_SUCCESS;
diff --git a/modules/demux/ttml.c b/modules/demux/ttml.c
index e671bd4..d0dcffd 100644
--- a/modules/demux/ttml.c
+++ b/modules/demux/ttml.c
@@ -32,7 +32,6 @@
 #include <vlc_strings.h>
 #include <vlc_memory.h>
 #include <vlc_es_out.h>
-#include <vlc_fixups.h>
 
 static int Open( vlc_object_t* p_this );
 static void Close( demux_t* p_demux );
@@ -456,28 +455,38 @@ static int Open( vlc_object_t* p_this )
 {
     demux_t     *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys;
+    p_demux->p_sys = p_sys = calloc( 1, sizeof( *p_sys ) );
+    if ( unlikely( p_sys == NULL ) )
+        return VLC_ENOMEM;
 
     uint8_t *p_peek;
-    ssize_t i_peek = stream_Peek( p_demux->s, (const uint8_t **) &p_peek, 128 );
-    if( i_peek < 32 || memcmp( p_peek, "<?xml", 5 ) ||
-        !strnstr( (const char *) p_peek, "<tt ", i_peek ) )
+    ssize_t i_peek = stream_Peek( p_demux->s, (const uint8_t **) &p_peek, 2048 );
+
+    if( unlikely( i_peek <= 0 ) )
+    {
+        Close( p_demux );
         return VLC_EGENERIC;
+    }
 
-    p_demux->p_sys = p_sys = calloc( 1, sizeof( *p_sys ) );
-    if ( unlikely( p_sys == NULL ) )
-        return VLC_ENOMEM;
+    stream_t *p_probestream = stream_MemoryNew( p_demux->s, p_peek, i_peek, true );
+    if( unlikely( !p_probestream ) )
+    {
+        Close( p_demux );
+        return VLC_EGENERIC;
+    }
 
     p_sys->p_xml = xml_Create( p_demux );
     if ( !p_sys->p_xml )
     {
         Close( p_demux );
+        stream_Delete( p_probestream );
         return VLC_EGENERIC;
     }
-
-    p_sys->p_reader = xml_ReaderCreate( p_sys->p_xml, p_demux->s );
+    p_sys->p_reader = xml_ReaderCreate( p_sys->p_xml, p_probestream );
     if ( !p_sys->p_reader )
     {
         Close( p_demux );
+        stream_Delete( p_probestream );
         return VLC_EGENERIC;
     }
 
@@ -486,8 +495,18 @@ static int Open( vlc_object_t* p_this )
     if ( i_type != XML_READER_STARTELEM || ( strcmp( psz_name, "tt" ) && strcmp( psz_name, "tt:tt" ) ) )
     {
         Close( p_demux );
+        stream_Delete( p_probestream );
         return VLC_EGENERIC;
     }
+
+    p_sys->p_reader = xml_ReaderReset( p_sys->p_reader, p_demux->s );
+    stream_Delete( p_probestream );
+    if ( !p_sys->p_reader )
+    {
+        Close( p_demux );
+        return VLC_EGENERIC;
+    }
+
     if ( ReadTTML( p_demux ) != VLC_SUCCESS )
     {
         Close( p_demux );



More information about the vlc-commits mailing list