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