[FFmpeg-devel] [PATCH] lavu/video_enc_params: make sure blocks are properly aligned

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Thu Apr 8 12:41:41 EEST 2021


Anton Khirnov:
> ---
>  libavutil/video_enc_params.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/libavutil/video_enc_params.c b/libavutil/video_enc_params.c
> index 635176ab91..1779a8799a 100644
> --- a/libavutil/video_enc_params.c
> +++ b/libavutil/video_enc_params.c
> @@ -30,9 +30,9 @@ AVVideoEncParams *av_video_enc_params_alloc(enum AVVideoEncParamsType type,
>                                              unsigned int nb_blocks, size_t *out_size)
>  {
>      AVVideoEncParams *par;
> -    size_t size;
> +    size_t blocks_offset = FFALIGN(sizeof(*par), 8);
> +    size_t size          = blocks_offset;
>  
> -    size = sizeof(*par);
>      if (nb_blocks > (SIZE_MAX - size) / sizeof(AVVideoBlockParams))
>          return NULL;
>      size += sizeof(AVVideoBlockParams) * nb_blocks;
> @@ -44,7 +44,7 @@ AVVideoEncParams *av_video_enc_params_alloc(enum AVVideoEncParamsType type,
>      par->type          = type;
>      par->nb_blocks     = nb_blocks;
>      par->block_size    = sizeof(AVVideoBlockParams);
> -    par->blocks_offset = sizeof(*par);
> +    par->blocks_offset = blocks_offset;
>  
>      if (out_size)
>          *out_size = size;
> 
Wouldn't it be safer to just define a struct { AVVideoEncParams header;
AVVideoBlockParams blocks[1]; } and use the offset of blocks in that?

- Andreas


More information about the ffmpeg-devel mailing list