[FFmpeg-devel] lavc/qsvenc: replace assert0 with an error return when pict_type is uninitialized

Submitted by Linjie Fu on Dec. 3, 2018, 8:34 a.m.

Details

Message ID 20181203083413.14086-1-linjie.fu@intel.com
State New
Headers show

Commit Message

Linjie Fu Dec. 3, 2018, 8:34 a.m.
pict_type may be uninitialized, and assert on a value coming from an external
library is not proper.

Return invalid data error in function ff_qsv_encode to avoid using uninitialized
value.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---
 libavcodec/qsvenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Zhong Li Dec. 5, 2018, 5:37 a.m.
> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf

> Of Linjie Fu

> Sent: Monday, December 3, 2018 4:34 PM

> To: ffmpeg-devel@ffmpeg.org

> Cc: Fu, Linjie <linjie.fu@intel.com>

> Subject: [FFmpeg-devel] [PATCH] lavc/qsvenc: replace assert0 with an error

> return when pict_type is uninitialized

> 

> pict_type may be uninitialized, and assert on a value coming from an

> external library is not proper.

> 

> Return invalid data error in function ff_qsv_encode to avoid using

> uninitialized value.

> 

> Signed-off-by: Linjie Fu <linjie.fu@intel.com>

> ---

>  libavcodec/qsvenc.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index

> 7f4592f878..891253be76 100644

> --- a/libavcodec/qsvenc.c

> +++ b/libavcodec/qsvenc.c

> @@ -1338,7 +1338,7 @@ int ff_qsv_encode(AVCodecContext *avctx,

> QSVEncContext *q,

>          else if (bs->FrameType & MFX_FRAMETYPE_B || bs->FrameType

> & MFX_FRAMETYPE_xB)

>              pict_type = AV_PICTURE_TYPE_B;

>          else

> -            av_assert0(!"Uninitialized pict_type!");

> +            return AVERROR_INVALIDDATA;


Thus will be still a broken issue of ticket # 7593.
As comment in the ticket, I prefer to set the picture type to be AV_PICTURE_TYPE_NONE when MSDK return an unknown frame type, 
And also give a warning log message. 

BTW, please give a short and brief subject. There is a guideline about how to write commit message can be a reference: https://chris.beams.io/posts/git-commit/
Carl Eugen Hoyos Dec. 5, 2018, 12:12 p.m.
2018-12-05 6:37 GMT+01:00, Li, Zhong <zhong.li@intel.com>:
>> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf
>> Of Linjie Fu
>> Sent: Monday, December 3, 2018 4:34 PM
>> To: ffmpeg-devel@ffmpeg.org
>> Cc: Fu, Linjie <linjie.fu@intel.com>
>> Subject: [FFmpeg-devel] [PATCH] lavc/qsvenc: replace assert0 with an
>> error
>> return when pict_type is uninitialized
>>
>> pict_type may be uninitialized, and assert on a value coming from an
>> external library is not proper.
>>
>> Return invalid data error in function ff_qsv_encode to avoid using
>> uninitialized value.
>>
>> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
>> ---
>>  libavcodec/qsvenc.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index
>> 7f4592f878..891253be76 100644
>> --- a/libavcodec/qsvenc.c
>> +++ b/libavcodec/qsvenc.c
>> @@ -1338,7 +1338,7 @@ int ff_qsv_encode(AVCodecContext *avctx,
>> QSVEncContext *q,
>>          else if (bs->FrameType & MFX_FRAMETYPE_B || bs->FrameType
>> & MFX_FRAMETYPE_xB)
>>              pict_type = AV_PICTURE_TYPE_B;
>>          else
>> -            av_assert0(!"Uninitialized pict_type!");
>> +            return AVERROR_INVALIDDATA;
>
> Thus will be still a broken issue of ticket # 7593.

But an important - and long discussed - bug would be replaced by a
graceful exit.

Carl Eugen

Patch hide | download patch | download mbox

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 7f4592f878..891253be76 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1338,7 +1338,7 @@  int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
         else if (bs->FrameType & MFX_FRAMETYPE_B || bs->FrameType & MFX_FRAMETYPE_xB)
             pict_type = AV_PICTURE_TYPE_B;
         else
-            av_assert0(!"Uninitialized pict_type!");
+            return AVERROR_INVALIDDATA;
 
 #if FF_API_CODED_FRAME
 FF_DISABLE_DEPRECATION_WARNINGS