diff --git a/libavformat/utils.c b/libavformat/utils.c
index 74ec667d910200207c27a425de454fa9fe7a5f96..3826df3f0abdd8e918ca23ef5b3093bc2a4c31b3 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1995,8 +1995,9 @@ int av_find_stream_info(AVFormatContext *ic)
             int i= st->parser->parser->split(st->codec, pkt->data, pkt->size);
             if(i){
                 st->codec->extradata_size= i;
-                st->codec->extradata= av_malloc(st->codec->extradata_size);
+                st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
                 memcpy(st->codec->extradata, pkt->data, st->codec->extradata_size);
+                memset(st->codec->extradata + i, 0, FF_INPUT_BUFFER_PADDING_SIZE);
             }
         }