[3/9] avcodec/extract_extradata: Zero-initialize the padding bytes in all allocated buffers

Message ID 20181003191538.33448-4-lu_zero@gentoo.org
State New
Headers show
Series
  • [1/9] avcodec/bsf: Add ff_bsf_get_packet_ref() function
Related show

Commit Message

Luca Barbato Oct. 3, 2018, 7:15 p.m.
From: James Almer <jamrial@gmail.com>

Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
---
 libavcodec/extract_extradata_bsf.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

James Almer Oct. 4, 2018, 2:59 a.m. | #1
On 10/3/2018 4:15 PM, Luca Barbato wrote:
> From: James Almer <jamrial@gmail.com>
> 
> Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
> Signed-off-by: James Almer <jamrial@gmail.com>
> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
> ---
>  libavcodec/extract_extradata_bsf.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c
> index 10d108054a..ed5d90b246 100644
> --- a/libavcodec/extract_extradata_bsf.c
> +++ b/libavcodec/extract_extradata_bsf.c
> @@ -114,6 +114,7 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,
>              ret = AVERROR(ENOMEM);
>              goto fail;
>          }
> +        memset(extradata + extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
>  
>          *data = extradata;
>          *size = extradata_size;
> @@ -137,6 +138,8 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,
>              pkt->buf  = filtered_buf;
>              pkt->data = filtered_buf->data;
>              pkt->size = filtered_data - filtered_buf->data;
> +
> +            memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
>          }
>      }
>  
> @@ -171,6 +174,7 @@ static int extract_extradata_vc1(AVBSFContext *ctx, AVPacket *pkt,
>              return AVERROR(ENOMEM);
>  
>          memcpy(*data, pkt->data, extradata_size);
> +        memset(*data + extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
>          *size = extradata_size;
>  
>          if (s->remove) {
> @@ -202,6 +206,8 @@ static int extract_extradata_mpeg124(AVBSFContext *ctx, AVPacket *pkt,
>                      return AVERROR(ENOMEM);
>  
>                  memcpy(*data, pkt->data, *size);
> +                memset(*data + *size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
> +                memset(*data + *size, 0, AV_INPUT_BUFFER_PADDING_SIZE);

Duplicated line.

LGTM otherwise.

>  
>                  if (s->remove) {
>                      pkt->data += *size;
>

Patch

diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c
index 10d108054a..ed5d90b246 100644
--- a/libavcodec/extract_extradata_bsf.c
+++ b/libavcodec/extract_extradata_bsf.c
@@ -114,6 +114,7 @@  static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,
             ret = AVERROR(ENOMEM);
             goto fail;
         }
+        memset(extradata + extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 
         *data = extradata;
         *size = extradata_size;
@@ -137,6 +138,8 @@  static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,
             pkt->buf  = filtered_buf;
             pkt->data = filtered_buf->data;
             pkt->size = filtered_data - filtered_buf->data;
+
+            memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
         }
     }
 
@@ -171,6 +174,7 @@  static int extract_extradata_vc1(AVBSFContext *ctx, AVPacket *pkt,
             return AVERROR(ENOMEM);
 
         memcpy(*data, pkt->data, extradata_size);
+        memset(*data + extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
         *size = extradata_size;
 
         if (s->remove) {
@@ -202,6 +206,8 @@  static int extract_extradata_mpeg124(AVBSFContext *ctx, AVPacket *pkt,
                     return AVERROR(ENOMEM);
 
                 memcpy(*data, pkt->data, *size);
+                memset(*data + *size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+                memset(*data + *size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 
                 if (s->remove) {
                     pkt->data += *size;