Commit bb1c56ea authored by Luca Barbato's avatar Luca Barbato Committed by Jean-Baptiste Kempf

avcodec: Always use av_malloc to alloc extradata

And always pad it while at it.
Codecs always expect extradata to be aligned and padded.

Prevent memory corruption when memalign-hack is enabled.
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 3bd43453
......@@ -96,7 +96,7 @@ static void InitDecoderConfig( decoder_t *p_dec, AVCodecContext *p_context )
if( i_size > 0 )
{
p_context->extradata =
malloc( i_size + FF_INPUT_BUFFER_PADDING_SIZE );
av_malloc( i_size + FF_INPUT_BUFFER_PADDING_SIZE );
if( p_context->extradata )
{
uint8_t *p_dst = p_context->extradata;
......@@ -234,7 +234,7 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
if( ffmpeg_OpenCodec( p_dec ) < 0 )
{
msg_Err( p_dec, "cannot open codec (%s)", p_sys->psz_namecodec );
free( p_sys->p_context->extradata );
av_free( p_sys->p_context->extradata );
free( p_sys );
return VLC_EGENERIC;
}
......
......@@ -359,7 +359,7 @@ static void CloseDecoder( vlc_object_t *p_this )
if( p_sys->p_context )
{
free( p_sys->p_context->extradata );
av_free( p_sys->p_context->extradata );
p_sys->p_context->extradata = NULL;
if( !p_sys->b_delayed_open )
......
......@@ -790,8 +790,9 @@ static void ffmpeg_InitCodec( decoder_t *p_dec )
uint8_t *p;
p_sys->p_context->extradata_size = i_size + 12;
p = p_sys->p_context->extradata =
malloc( p_sys->p_context->extradata_size );
p = p_sys->p_context->extradata =
av_malloc( p_sys->p_context->extradata_size +
FF_INPUT_BUFFER_PADDING_SIZE );
if( !p )
return;
......@@ -828,12 +829,12 @@ static void ffmpeg_InitCodec( decoder_t *p_dec )
{
p_sys->p_context->extradata_size = i_size;
p_sys->p_context->extradata =
malloc( i_size + FF_INPUT_BUFFER_PADDING_SIZE );
av_malloc( i_size + FF_INPUT_BUFFER_PADDING_SIZE );
if( p_sys->p_context->extradata )
{
memcpy( p_sys->p_context->extradata,
p_dec->fmt_in.p_extra, i_size );
memset( &((uint8_t*)p_sys->p_context->extradata)[i_size],
memset( p_sys->p_context->extradata + i_size,
0, FF_INPUT_BUFFER_PADDING_SIZE );
}
}
......
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