diff mbox

[FFmpeg-devel,1/3] lavc/utils: disallow zero sized packets with data set in avcodec_send_packet

Message ID 1475227747-11938-1-git-send-email-cus@passwd.hu
State Accepted
Commit 2face3e7b568daf70f3115126b81d5793301569c
Headers show

Commit Message

Marton Balint Sept. 30, 2016, 9:29 a.m. UTC
Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavcodec/utils.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

wm4 Sept. 30, 2016, 9:40 a.m. UTC | #1
On Fri, 30 Sep 2016 11:29:05 +0200
Marton Balint <cus@passwd.hu> wrote:

> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>  libavcodec/utils.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index cf85300..d0a6817 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -2813,6 +2813,9 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacke
>      if (avctx->internal->draining)
>          return AVERROR_EOF;
>  
> +    if (avpkt && !avpkt->size && avpkt->data)
> +        return AVERROR(EINVAL);
> +
>      if (!avpkt || !avpkt->size) {
>          avctx->internal->draining = 1;
>          avpkt = NULL;

This means packet with size==0 with data!=NULL will be rejected,
instead of being interpreted as flush packets.

Fine with me. Still allows "normal" flush packets, and probably
prevents that API users accidentally enter the EOF state by sending such
packets.
Hendrik Leppkes Sept. 30, 2016, 11:04 a.m. UTC | #2
On Fri, Sep 30, 2016 at 11:40 AM, wm4 <nfxjfg@googlemail.com> wrote:
> On Fri, 30 Sep 2016 11:29:05 +0200
> Marton Balint <cus@passwd.hu> wrote:
>
>> Signed-off-by: Marton Balint <cus@passwd.hu>
>> ---
>>  libavcodec/utils.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
>> index cf85300..d0a6817 100644
>> --- a/libavcodec/utils.c
>> +++ b/libavcodec/utils.c
>> @@ -2813,6 +2813,9 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacke
>>      if (avctx->internal->draining)
>>          return AVERROR_EOF;
>>
>> +    if (avpkt && !avpkt->size && avpkt->data)
>> +        return AVERROR(EINVAL);
>> +
>>      if (!avpkt || !avpkt->size) {
>>          avctx->internal->draining = 1;
>>          avpkt = NULL;
>
> This means packet with size==0 with data!=NULL will be rejected,
> instead of being interpreted as flush packets.
>
> Fine with me. Still allows "normal" flush packets, and probably
> prevents that API users accidentally enter the EOF state by sending such
> packets.

I agree, such a packet would likely not be meant as a flush packet,
and may induce unexpected behavior.

- Hendrik
Marton Balint Oct. 3, 2016, 8:37 p.m. UTC | #3
On Fri, 30 Sep 2016, Hendrik Leppkes wrote:

> On Fri, Sep 30, 2016 at 11:40 AM, wm4 <nfxjfg@googlemail.com> wrote:
>> On Fri, 30 Sep 2016 11:29:05 +0200
>> Marton Balint <cus@passwd.hu> wrote:
>>
>>> Signed-off-by: Marton Balint <cus@passwd.hu>
>>> ---
>>>  libavcodec/utils.c | 3 +++
>>>  1 file changed, 3 insertions(+)
>>>
>>> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
>>> index cf85300..d0a6817 100644
>>> --- a/libavcodec/utils.c
>>> +++ b/libavcodec/utils.c
>>> @@ -2813,6 +2813,9 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacke
>>>      if (avctx->internal->draining)
>>>          return AVERROR_EOF;
>>>
>>> +    if (avpkt && !avpkt->size && avpkt->data)
>>> +        return AVERROR(EINVAL);
>>> +
>>>      if (!avpkt || !avpkt->size) {
>>>          avctx->internal->draining = 1;
>>>          avpkt = NULL;
>>
>> This means packet with size==0 with data!=NULL will be rejected,
>> instead of being interpreted as flush packets.
>>
>> Fine with me. Still allows "normal" flush packets, and probably
>> prevents that API users accidentally enter the EOF state by sending such
>> packets.
>
> I agree, such a packet would likely not be meant as a flush packet,
> and may induce unexpected behavior.
>

Thanks, pushed.

Regards,
Marton
diff mbox

Patch

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index cf85300..d0a6817 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -2813,6 +2813,9 @@  int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacke
     if (avctx->internal->draining)
         return AVERROR_EOF;
 
+    if (avpkt && !avpkt->size && avpkt->data)
+        return AVERROR(EINVAL);
+
     if (!avpkt || !avpkt->size) {
         avctx->internal->draining = 1;
         avpkt = NULL;