Commit 0c4c45e3 authored by Rafaël Carré's avatar Rafaël Carré

xiph_SplitHeaders: do not malloc+memcpy headers

Directly point into the provided extra data
The headers were always used then freed immediately
parent 311180df
......@@ -515,21 +515,18 @@ static int ProcessHeaders( decoder_t *p_dec )
if( xiph_SplitHeaders( pi_size, pp_data, &i_count,
p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) )
return VLC_EGENERIC;
int i_ret = VLC_SUCCESS;
if( i_count < 1 )
{
i_ret = VLC_EGENERIC;
goto end;
}
return VLC_EGENERIC;
/* Take care of the initial Kate header */
kp.nbytes = pi_size[0];
kp.data = pp_data[0];
i_ret = kate_decode_headerin( &p_sys->ki, &p_sys->kc, &kp );
int i_ret = kate_decode_headerin( &p_sys->ki, &p_sys->kc, &kp );
if( i_ret < 0 )
{
msg_Err( p_dec, "this bitstream does not contain Kate data (%d)", i_ret );
goto end;
return VLC_EGENERIC;
}
msg_Dbg( p_dec, "%s %s text, granule rate %f, granule shift %d",
......@@ -546,7 +543,7 @@ static int ProcessHeaders( decoder_t *p_dec )
if( i_ret < 0 )
{
msg_Err( p_dec, "Kate header %d is corrupted: %d", i_headeridx, i_ret );
goto end;
return VLC_EGENERIC;
}
/* header 1 is comments */
......@@ -581,10 +578,7 @@ static int ProcessHeaders( decoder_t *p_dec )
}
#endif
end:
for( unsigned i = 0; i < i_count; i++ )
free( pp_data[i] );
return i_ret < 0 ? VLC_EGENERIC : VLC_SUCCESS;
return VLC_SUCCESS;
}
/*****************************************************************************
......
......@@ -241,13 +241,12 @@ static int ProcessHeaders( decoder_t *p_dec )
unsigned pi_size[XIPH_MAX_HEADER_COUNT];
void *pp_data[XIPH_MAX_HEADER_COUNT];
unsigned i_count;
int ret = VLC_EGENERIC;
if( xiph_SplitHeaders( pi_size, pp_data, &i_count,
p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) )
return VLC_EGENERIC;
if( i_count < 2 )
goto end;
return VLC_EGENERIC;;
oggpacket.granulepos = -1;
oggpacket.e_o_s = 0;
......@@ -257,15 +256,11 @@ static int ProcessHeaders( decoder_t *p_dec )
oggpacket.b_o_s = 1; /* yes this actually is a b_o_s packet :) */
oggpacket.bytes = pi_size[0];
oggpacket.packet = pp_data[0];
ret = ProcessInitialHeader( p_dec, &oggpacket );
int ret = ProcessInitialHeader( p_dec, &oggpacket );
if (ret != VLC_SUCCESS)
msg_Err( p_dec, "initial Opus header is corrupted" );
end:
for( unsigned i = 0; i < i_count; i++ )
free( pp_data[i] );
return ret;
}
......
......@@ -326,7 +326,7 @@ static int ProcessHeaders( decoder_t *p_dec )
p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) )
return VLC_EGENERIC;
if( i_count < 2 )
goto error;
return VLC_EGENERIC;;
oggpacket.granulepos = -1;
oggpacket.e_o_s = 0;
......@@ -339,7 +339,7 @@ static int ProcessHeaders( decoder_t *p_dec )
if( ProcessInitialHeader( p_dec, &oggpacket ) != VLC_SUCCESS )
{
msg_Err( p_dec, "initial Speex header is corrupted" );
goto error;
return VLC_EGENERIC;;
}
/* The next packet in order is the comments header */
......@@ -357,14 +357,7 @@ static int ProcessHeaders( decoder_t *p_dec )
p_dec->fmt_in.p_extra, p_dec->fmt_out.i_extra );
}
for( unsigned i = 0; i < i_count; i++ )
free( pp_data[i] );
return VLC_SUCCESS;
error:
for( unsigned i = 0; i < i_count; i++ )
free( pp_data[i] );
return VLC_EGENERIC;
}
/*****************************************************************************
......
......@@ -249,7 +249,7 @@ static int ProcessHeaders( decoder_t *p_dec )
p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) )
return VLC_EGENERIC;
if( i_count < 3 )
goto error;
return VLC_EGENERIC;
oggpacket.granulepos = -1;
oggpacket.e_o_s = 0;
......@@ -404,15 +404,11 @@ static int ProcessHeaders( decoder_t *p_dec )
p_dec->fmt_in.p_extra, p_dec->fmt_out.i_extra );
}
for( unsigned i = 0; i < i_count; i++ )
free( pp_data[i] );
/* Clean up the decoder setup info... we're done with it */
th_setup_free( ts );
return VLC_SUCCESS;
error:
for( unsigned i = 0; i < i_count; i++ )
free( pp_data[i] );
/* Clean up the decoder setup info... we're done with it */
th_setup_free( ts );
return VLC_EGENERIC;
......
......@@ -342,7 +342,7 @@ static int ProcessHeaders( decoder_t *p_dec )
p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) )
return VLC_EGENERIC;
if( i_count < 3 )
goto error;
return VLC_EGENERIC;
oggpacket.granulepos = -1;
oggpacket.e_o_s = 0;
......@@ -355,7 +355,7 @@ static int ProcessHeaders( decoder_t *p_dec )
if( vorbis_synthesis_headerin( &p_sys->vi, &p_sys->vc, &oggpacket ) < 0 )
{
msg_Err( p_dec, "this bitstream does not contain Vorbis audio data");
goto error;
return VLC_EGENERIC;
}
/* Setup the format */
......@@ -366,7 +366,7 @@ static int ProcessHeaders( decoder_t *p_dec )
{
msg_Err( p_dec, "invalid number of channels (not between 1 and 9): %i",
p_dec->fmt_out.audio.i_channels );
goto error;
return VLC_EGENERIC;
}
p_dec->fmt_out.audio.i_physical_channels =
......@@ -386,7 +386,7 @@ static int ProcessHeaders( decoder_t *p_dec )
if( vorbis_synthesis_headerin( &p_sys->vi, &p_sys->vc, &oggpacket ) < 0 )
{
msg_Err( p_dec, "2nd Vorbis header is corrupted" );
goto error;
return VLC_EGENERIC;
}
ParseVorbisComments( p_dec );
......@@ -420,14 +420,7 @@ static int ProcessHeaders( decoder_t *p_dec )
ConfigureChannelOrder(p_sys->pi_chan_table, p_sys->vi.channels,
p_dec->fmt_out.audio.i_physical_channels, true);
for( unsigned i = 0; i < i_count; i++ )
free( pp_data[i] );
return VLC_SUCCESS;
error:
for( unsigned i = 0; i < i_count; i++ )
free( pp_data[i] );
return VLC_EGENERIC;
}
/*****************************************************************************
......
......@@ -1949,10 +1949,6 @@ static bool Ogg_IsVorbisFormatCompatible( const es_format_t *p_new, const es_for
b_match = false;
}
for( unsigned i = 0; i < i_new_count; i++ )
free( pp_new_data[i] );
for( unsigned i = 0; i < i_old_count; i++ )
free( pp_old_data[i] );
return b_match;
}
......@@ -2033,10 +2029,7 @@ static bool Ogg_IsOpusFormatCompatible( const es_format_t *p_new,
memcmp(p_old_map, p_new_map,
i_new_channel_count*sizeof(*p_new_map)) == 0;
}
for( unsigned i = 0; i < i_new_count; i++ )
free( pp_new_data[i] );
for( unsigned i = 0; i < i_old_count; i++ )
free( pp_old_data[i] );
return b_match;
}
......@@ -2114,9 +2107,6 @@ static void Ogg_ExtractXiphMeta( demux_t *p_demux, es_format_t *p_fmt,
{
p_demux->info.i_update |= INPUT_UPDATE_TITLE_LIST;
}
for( unsigned i = 0; i < i_count; i++ )
free( pp_data[i] );
}
static void Ogg_ExtractMeta( demux_t *p_demux, es_format_t *p_fmt, const uint8_t *p_headers, int i_headers )
{
......
......@@ -25,9 +25,9 @@
#define XIPH_MAX_HEADER_COUNT (256)
static inline int xiph_SplitHeaders(unsigned packet_size[], void *packet[], unsigned *packet_count,
unsigned extra_size, const void *extra)
unsigned extra_size, void *extra)
{
const uint8_t *current = (const uint8_t*)extra;
uint8_t *current = extra;
const uint8_t *end = &current[extra_size];
if (extra_size < 1)
return VLC_EGENERIC;
......@@ -52,19 +52,12 @@ static inline int xiph_SplitHeaders(unsigned packet_size[], void *packet[], unsi
return VLC_EGENERIC;
packet_size[count - 1] = end - current - size;
/* Copy the payloads */
for (unsigned i = 0; i < count; i++) {
packet[i] = malloc(packet_size[i]);
if (!packet[i]) {
for (unsigned j = 0; j < i; j++)
free(packet[j]);
return VLC_ENOMEM;
}
for (unsigned i = 0; i < count; i++)
if (packet_size[i] > 0) {
memcpy(packet[i], current, packet_size[i]);
packet[i] = current;
current += packet_size[i];
}
}
return VLC_SUCCESS;
}
......@@ -131,7 +124,7 @@ static inline int xiph_AppendHeaders(int *extra_size, void **extra,
if (count >= XIPH_MAX_HEADER_COUNT)
return VLC_EGENERIC;
free(*extra);
void *old = *extra;
packet_size[count] = size;
packet[count] = (void*)data;
......@@ -140,8 +133,8 @@ static inline int xiph_AppendHeaders(int *extra_size, void **extra,
*extra_size = 0;
*extra = NULL;
}
for (unsigned i = 0; i < count; i++)
free(packet[i]);
free(old);
if (*extra_size <= 0)
return VLC_EGENERIC;
......
......@@ -664,9 +664,6 @@ static block_t *OggCreateHeader( sout_mux_t *p_mux )
p_stream->i_keyframe_granule_shift =
( (op.packet[40] & 0x03) << 3 ) | ( (op.packet[41] & 0xe0) >> 5 );
}
for( unsigned i = 0; i < i_count; i++ )
free( pp_data[i] );
}
else if( p_stream->i_fourcc == VLC_CODEC_DIRAC )
{
......@@ -751,8 +748,6 @@ static block_t *OggCreateHeader( sout_mux_t *p_mux )
if( p_og )
block_ChainAppend( &p_hdr, p_og );
}
for( unsigned i = 0; i < i_count; i++ )
free( pp_data[i] );
}
else if( p_stream->i_fourcc != VLC_CODEC_FLAC &&
p_stream->i_fourcc != VLC_CODEC_DIRAC )
......
......@@ -65,23 +65,16 @@ static int rtp_xiph_pack_headers(size_t room, void *p_extra, size_t i_extra,
unsigned packet_size[XIPH_MAX_HEADER_COUNT];
void *packet[XIPH_MAX_HEADER_COUNT];
unsigned packet_count;
int val = xiph_SplitHeaders(packet_size, packet, &packet_count,
i_extra, p_extra);
if (val != VLC_SUCCESS)
return val;
if (xiph_SplitHeaders(packet_size, packet, &packet_count,
i_extra, p_extra))
return VLC_EGENERIC;;
if (packet_count < 3)
{
val = VLC_EGENERIC;
goto free;
}
return VLC_EGENERIC;;
if (theora_pixel_fmt != NULL)
{
if (packet_size[0] < 42)
{
val = VLC_EGENERIC;
goto free;
}
return VLC_EGENERIC;
*theora_pixel_fmt = (((uint8_t *)packet[0])[41] >> 3) & 0x03;
}
......@@ -100,10 +93,7 @@ static int rtp_xiph_pack_headers(size_t room, void *p_extra, size_t i_extra,
+ packet_size[0] + packet_size[1] + packet_size[2];
*p_buffer = malloc(*i_buffer);
if (*p_buffer == NULL)
{
val = VLC_ENOMEM;
goto free;
}
return VLC_ENOMEM;
uint8_t *p = *p_buffer + room;
/* Number of headers */
......@@ -126,12 +116,7 @@ static int rtp_xiph_pack_headers(size_t room, void *p_extra, size_t i_extra,
p += packet_size[i];
}
val = VLC_SUCCESS;
free:
for (unsigned i = 0; i < packet_count; i++)
free(packet[i]);
return val;
return VLC_SUCCESS;
}
static char *rtp_xiph_b64_oob_config(void *p_extra, size_t i_extra,
......
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