X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdemux%2Fa52.c;h=defb32b3b579a9f1e8b19781512d98f1ea3df044;hb=a5c83dda798f93cc7a76bbb50d89352117e6ec46;hp=378f8e62dc22c0108d1ff3684e6f509b7a3dff18;hpb=57bbabb5e7c4b33141fdfbd811c78120e2401a9f;p=vlc diff --git a/modules/demux/a52.c b/modules/demux/a52.c index 378f8e62dc..defb32b3b5 100644 --- a/modules/demux/a52.c +++ b/modules/demux/a52.c @@ -28,7 +28,8 @@ # include "config.h" #endif -#include +#include +#include #include #include @@ -45,7 +46,7 @@ static void Close ( vlc_object_t * ); vlc_module_begin(); set_category( CAT_INPUT ); set_subcategory( SUBCAT_INPUT_DEMUX ); - set_description( _("Raw A/52 demuxer") ); + set_description( N_("Raw A/52 demuxer") ); set_capability( "demux", 145 ); set_callbacks( Open, Close ); add_shortcut( "a52" ); @@ -73,9 +74,9 @@ static int CheckSync( const uint8_t *p_peek, bool *p_big_endian ); #define PCM_FRAME_SIZE (1536 * 4) #define A52_PACKET_SIZE (4 * PCM_FRAME_SIZE) +#define A52_PROBE_SIZE (512*1024) #define A52_MAX_HEADER_SIZE 10 - /***************************************************************************** * Open: initializes ES structures *****************************************************************************/ @@ -83,29 +84,32 @@ static int Open( vlc_object_t * p_this ) { demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; - const byte_t*p_peek; + const uint8_t *p_peek; int i_peek = 0; bool b_big_endian = 0; /* Arbitrary initialisation */ /* Check if we are dealing with a WAV file */ - if( stream_Peek( p_demux->s, &p_peek, 12 ) == 12 && - !memcmp( p_peek, "RIFF", 4 ) && !memcmp( p_peek + 8, "WAVE", 4 ) ) + if( stream_Peek( p_demux->s, &p_peek, 12+8 ) == 12+8 && + !memcmp( p_peek, "RIFF", 4 ) && !memcmp( &p_peek[8], "WAVE", 4 ) ) { - int i_size; - /* Skip the wave header */ i_peek = 12 + 8; - while( stream_Peek( p_demux->s, &p_peek, i_peek ) == i_peek && - memcmp( p_peek + i_peek - 8, "data", 4 ) ) + while( memcmp( p_peek + i_peek - 8, "data", 4 ) ) { - i_peek += GetDWLE( p_peek + i_peek - 4 ) + 8; + uint32_t i_len = GetDWLE( p_peek + i_peek - 4 ); + if( i_len > A52_PROBE_SIZE || i_peek + i_len > A52_PROBE_SIZE ) + return VLC_EGENERIC; + + i_peek += i_len + 8; + if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek ) + return VLC_EGENERIC; } /* TODO: should check wave format and sample_rate */ /* Some A52 wav files don't begin with a sync code so we do a more * extensive search */ - i_size = stream_Peek( p_demux->s, &p_peek, i_peek + A52_PACKET_SIZE * 2); + int i_size = stream_Peek( p_demux->s, &p_peek, i_peek + A52_PACKET_SIZE * 2); i_size -= (PCM_FRAME_SIZE + A52_MAX_HEADER_SIZE); while( i_peek < i_size ) @@ -197,7 +201,7 @@ static int Demux( demux_t *p_demux ) #else int i; - byte_t *p_tmp, tmp; + uint8_t *p_tmp, tmp; p_tmp = p_block_in->p_buffer; for( i = p_block_in->i_buffer / 2 ; i-- ; ) { @@ -227,7 +231,7 @@ static int Demux( demux_t *p_demux ) if( p_block_out->i_length ) { p_sys->i_mux_rate = - p_block_out->i_buffer * I64C(1000000)/p_block_out->i_length; + p_block_out->i_buffer * INT64_C(1000000)/p_block_out->i_length; } /* set PCR */