vlc | branch: master | Luca Barbato <lu_z...@gentoo.org> | Wed Oct 23 12:17:02 2013 +0200| [bb1c56ea79ba7bd82d5a3be779c4903f1269a72e] | committer: 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: Jean-Baptiste Kempf <j...@videolan.org> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bb1c56ea79ba7bd82d5a3be779c4903f1269a72e --- 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 3098ab9..543640f 100644 --- a/modules/codec/avcodec/video.c +++ b/modules/codec/avcodec/video.c @@ -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 ); } } _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits