diff --git a/libavformat/hevc.c b/libavformat/hevc.c
index 4d43b6a0836a67c7e5a541bd50c28b7cfca06154..26db3b101f052e67e0a6fb565183c48e37611927 100644
--- a/libavformat/hevc.c
+++ b/libavformat/hevc.c
@@ -636,7 +636,7 @@ static uint8_t *nal_unit_extract_rbsp(const uint8_t *src, uint32_t src_len,
     uint8_t *dst;
     uint32_t i, len;
 
-    dst = av_malloc(src_len);
+    dst = av_malloc(src_len + FF_INPUT_BUFFER_PADDING_SIZE);
     if (!dst)
         return NULL;