Commit 9ea1737f authored by Francois Cartegnie's avatar Francois Cartegnie

demux: ttml: fix xml parsing

Restores and fixes 7ce48b0d

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