[vlc-devel] [PATCH] avcodec: Always use av_malloc to alloc extradata
Luca Barbato
lu_zero at gentoo.org
Wed Oct 23 12:17:02 CEST 2013
And always pad it while at it.
Codecs always expect extradata to be aligned and padded.
Prevent memory corruption when memalign-hack is enabled.
---
Now taking care hopefully of all the cases.
modules/codec/avcodec/audio.c | 4 ++--
modules/codec/avcodec/avcodec.c | 2 +-
modules/codec/avcodec/video.c | 9 +++++----
3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index aa89255..5c4de03 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -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;
}
diff --git a/modules/codec/avcodec/avcodec.c b/modules/codec/avcodec/avcodec.c
index c722063..d403202 100644
--- a/modules/codec/avcodec/avcodec.c
+++ b/modules/codec/avcodec/avcodec.c
@@ -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 )
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 5ac682f..c6a3457 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -773,8 +773,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;
@@ -811,12 +812,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 );
}
}
--
1.8.3.2
More information about the vlc-devel
mailing list