diff mbox

[FFmpeg-devel,2/3] hwcontext_vaapi: Return error if can not find a VA RT format

Message ID 20180504144107.16201-2-haihao.xiang@intel.com
State New
Headers show

Commit Message

Xiang, Haihao May 4, 2018, 2:41 p.m. UTC
Otherwise va_rt_format might be unitialized

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
 libavutil/hwcontext_vaapi.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Mark Thompson May 7, 2018, 8:48 p.m. UTC | #1
On 04/05/18 15:41, Haihao Xiang wrote:
> Otherwise va_rt_format might be unitialized
> 
> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> ---
>  libavutil/hwcontext_vaapi.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
> index 7daaa951cc..e59042487d 100644
> --- a/libavutil/hwcontext_vaapi.c
> +++ b/libavutil/hwcontext_vaapi.c
> @@ -1028,6 +1028,11 @@ static int vaapi_map_from_drm(AVHWFramesContext *src_fc, AVFrame *dst,
>              va_rt_format = vaapi_format_map[i].rt_format;
>      }
>  
> +    if (i >= FF_ARRAY_ELEMS(vaapi_format_map)) {
> +        av_log(dst_fc, AV_LOG_ERROR, "No matching VA RT format \n");
> +        return AVERROR(EINVAL);
> +    }
> +
>      buffer_handle = desc->objects[0].fd;
>      buffer_desc.pixel_format = va_fourcc;
>      buffer_desc.width        = src_fc->width;
> 

How would you hit this case?  Every fourcc in vaapi_drm_format_map is also present in vaapi_format_map.

- Mark
Xiang, Haihao May 8, 2018, 2:53 a.m. UTC | #2
On Mon, 2018-05-07 at 21:48 +0100, Mark Thompson wrote:
> On 04/05/18 15:41, Haihao Xiang wrote:

> > Otherwise va_rt_format might be unitialized

> > 

> > Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>

> > ---

> >  libavutil/hwcontext_vaapi.c | 5 +++++

> >  1 file changed, 5 insertions(+)

> > 

> > diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c

> > index 7daaa951cc..e59042487d 100644

> > --- a/libavutil/hwcontext_vaapi.c

> > +++ b/libavutil/hwcontext_vaapi.c

> > @@ -1028,6 +1028,11 @@ static int vaapi_map_from_drm(AVHWFramesContext

> > *src_fc, AVFrame *dst,

> >              va_rt_format = vaapi_format_map[i].rt_format;

> >      }

> >  

> > +    if (i >= FF_ARRAY_ELEMS(vaapi_format_map)) {

> > +        av_log(dst_fc, AV_LOG_ERROR, "No matching VA RT format \n");

> > +        return AVERROR(EINVAL);

> > +    }

> > +

> >      buffer_handle = desc->objects[0].fd;

> >      buffer_desc.pixel_format = va_fourcc;

> >      buffer_desc.width        = src_fc->width;

> > 

> 

> How would you hit this case?  Every fourcc in vaapi_drm_format_map is also

> present in vaapi_format_map.


It is reported by static analysis tool as well. I think adding a check here make
s sure the relationship between vaapi_drm_format_map and vaapi_format_map. or
how about av_assert0(i < FF_ARRAY_ELEMS(vaapi_format_map)) if you don't want to
add the if()?

> 

> - Mark

> _______________________________________________

> ffmpeg-devel mailing list

> ffmpeg-devel@ffmpeg.org

> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Mark Thompson May 8, 2018, 9:37 p.m. UTC | #3
On 08/05/18 03:53, Xiang, Haihao wrote:
> On Mon, 2018-05-07 at 21:48 +0100, Mark Thompson wrote:
>> On 04/05/18 15:41, Haihao Xiang wrote:
>>> Otherwise va_rt_format might be unitialized
>>>
>>> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
>>> ---
>>>  libavutil/hwcontext_vaapi.c | 5 +++++
>>>  1 file changed, 5 insertions(+)
>>>
>>> diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
>>> index 7daaa951cc..e59042487d 100644
>>> --- a/libavutil/hwcontext_vaapi.c
>>> +++ b/libavutil/hwcontext_vaapi.c
>>> @@ -1028,6 +1028,11 @@ static int vaapi_map_from_drm(AVHWFramesContext
>>> *src_fc, AVFrame *dst,
>>>              va_rt_format = vaapi_format_map[i].rt_format;
>>>      }
>>>  
>>> +    if (i >= FF_ARRAY_ELEMS(vaapi_format_map)) {
>>> +        av_log(dst_fc, AV_LOG_ERROR, "No matching VA RT format \n");
>>> +        return AVERROR(EINVAL);
>>> +    }
>>> +
>>>      buffer_handle = desc->objects[0].fd;
>>>      buffer_desc.pixel_format = va_fourcc;
>>>      buffer_desc.width        = src_fc->width;
>>>
>>
>> How would you hit this case?  Every fourcc in vaapi_drm_format_map is also
>> present in vaapi_format_map.
> 
> It is reported by static analysis tool as well. I think adding a check here make
> s sure the relationship between vaapi_drm_format_map and vaapi_format_map. or
> how about av_assert0(i < FF_ARRAY_ELEMS(vaapi_format_map)) if you don't want to
> add the if()?

An assert feels better to me - it's our bug if a fourcc in vaapi_drm_format_map isn't in vaapi_format_map, returning an error to the user is not helpful.

Thanks,

- Mark
Xiang, Haihao May 9, 2018, 4:30 a.m. UTC | #4
On Tue, 2018-05-08 at 22:37 +0100, Mark Thompson wrote:
> On 08/05/18 03:53, Xiang, Haihao wrote:

> > On Mon, 2018-05-07 at 21:48 +0100, Mark Thompson wrote:

> > > On 04/05/18 15:41, Haihao Xiang wrote:

> > > > Otherwise va_rt_format might be unitialized

> > > > 

> > > > Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>

> > > > ---

> > > >  libavutil/hwcontext_vaapi.c | 5 +++++

> > > >  1 file changed, 5 insertions(+)

> > > > 

> > > > diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c

> > > > index 7daaa951cc..e59042487d 100644

> > > > --- a/libavutil/hwcontext_vaapi.c

> > > > +++ b/libavutil/hwcontext_vaapi.c

> > > > @@ -1028,6 +1028,11 @@ static int vaapi_map_from_drm(AVHWFramesContext

> > > > *src_fc, AVFrame *dst,

> > > >              va_rt_format = vaapi_format_map[i].rt_format;

> > > >      }

> > > >  

> > > > +    if (i >= FF_ARRAY_ELEMS(vaapi_format_map)) {

> > > > +        av_log(dst_fc, AV_LOG_ERROR, "No matching VA RT format \n");

> > > > +        return AVERROR(EINVAL);

> > > > +    }

> > > > +

> > > >      buffer_handle = desc->objects[0].fd;

> > > >      buffer_desc.pixel_format = va_fourcc;

> > > >      buffer_desc.width        = src_fc->width;

> > > > 

> > > 

> > > How would you hit this case?  Every fourcc in vaapi_drm_format_map is also

> > > present in vaapi_format_map.

> > 

> > It is reported by static analysis tool as well. I think adding a check here

> > make

> > s sure the relationship between vaapi_drm_format_map and vaapi_format_map.

> > or

> > how about av_assert0(i < FF_ARRAY_ELEMS(vaapi_format_map)) if you don't want

> > to

> > add the if()?

> 

> An assert feels better to me - it's our bug if a fourcc in

> vaapi_drm_format_map isn't in vaapi_format_map, returning an error to the user

> is not helpful.


Agree, I will update the patch.

Thanks
Haihao

> 

> Thanks,

> 

> - Mark

> _______________________________________________

> ffmpeg-devel mailing list

> ffmpeg-devel@ffmpeg.org

> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
diff mbox

Patch

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 7daaa951cc..e59042487d 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -1028,6 +1028,11 @@  static int vaapi_map_from_drm(AVHWFramesContext *src_fc, AVFrame *dst,
             va_rt_format = vaapi_format_map[i].rt_format;
     }
 
+    if (i >= FF_ARRAY_ELEMS(vaapi_format_map)) {
+        av_log(dst_fc, AV_LOG_ERROR, "No matching VA RT format \n");
+        return AVERROR(EINVAL);
+    }
+
     buffer_handle = desc->objects[0].fd;
     buffer_desc.pixel_format = va_fourcc;
     buffer_desc.width        = src_fc->width;