diff mbox

[FFmpeg-devel] pngdec: check if previous frame exists instead of trusting sequence_number

Message ID 285a0213-2a77-fa4c-4412-e1f296423e14@googlemail.com
State Accepted
Headers show

Commit Message

Andreas Cadhalpun Nov. 26, 2016, 10:36 p.m. UTC
On 26.11.2016 01:53, Michael Niedermayer wrote:
> On Fri, Nov 25, 2016 at 10:13:06PM +0100, Andreas Cadhalpun wrote:
>> This fixes a segmentation fault caused by calling memcpy with NULL as
>> second argument in handle_p_frame_apng.
>>
>> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
>> ---
>>  libavcodec/pngdec.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
>> index 36275ae..a7b330b 100644
>> --- a/libavcodec/pngdec.c
>> +++ b/libavcodec/pngdec.c
>> @@ -922,7 +922,7 @@ static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s,
>>          return AVERROR_INVALIDDATA;
>>      }
>>  
>> -    if (sequence_number == 0 && dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
>> +    if (!s->previous_picture.f->data[0] && dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
>>          // No previous frame to revert to for the first frame
>>          // Spec says to just treat it as a APNG_DISPOSE_OP_BACKGROUND
>>          dispose_op = APNG_DISPOSE_OP_BACKGROUND;
> 
> wont this be different when seeking back to the
> first frame ?
> is that intended ?

I don't think the apng demuxer supports seeking.
But it shouldn't hurt to check both sequence_number and the previous frame.
Updated patch is attached.

Best regards,
Andreas

Comments

Michael Niedermayer Nov. 27, 2016, 3:07 a.m. UTC | #1
On Sat, Nov 26, 2016 at 11:36:48PM +0100, Andreas Cadhalpun wrote:
> On 26.11.2016 01:53, Michael Niedermayer wrote:
> > On Fri, Nov 25, 2016 at 10:13:06PM +0100, Andreas Cadhalpun wrote:
> >> This fixes a segmentation fault caused by calling memcpy with NULL as
> >> second argument in handle_p_frame_apng.
> >>
> >> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
> >> ---
> >>  libavcodec/pngdec.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
> >> index 36275ae..a7b330b 100644
> >> --- a/libavcodec/pngdec.c
> >> +++ b/libavcodec/pngdec.c
> >> @@ -922,7 +922,7 @@ static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s,
> >>          return AVERROR_INVALIDDATA;
> >>      }
> >>  
> >> -    if (sequence_number == 0 && dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
> >> +    if (!s->previous_picture.f->data[0] && dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
> >>          // No previous frame to revert to for the first frame
> >>          // Spec says to just treat it as a APNG_DISPOSE_OP_BACKGROUND
> >>          dispose_op = APNG_DISPOSE_OP_BACKGROUND;
> > 
> > wont this be different when seeking back to the
> > first frame ?
> > is that intended ?
> 
> I don't think the apng demuxer supports seeking.
> But it shouldn't hurt to check both sequence_number and the previous frame.
> Updated patch is attached.
> 
> Best regards,
> Andreas
> 

>  pngdec.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 141d5230c97dbc47e0b291f660544cfe57abbf7c  0001-pngdec-check-if-previous-frame-exists-instead-of-tru.patch
> From 84125e5f32fd4b9146d9926d2f8a4467da7c8557 Mon Sep 17 00:00:00 2001
> From: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
> Date: Fri, 25 Nov 2016 22:09:51 +0100
> Subject: [PATCH] pngdec: check if previous frame exists instead of trusting
>  sequence_number
> 
> This fixes a segmentation fault caused by calling memcpy with NULL as
> second argument in handle_p_frame_apng.
> 
> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
> ---
>  libavcodec/pngdec.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

LGTM

thx


[...]
Andreas Cadhalpun Nov. 27, 2016, 10:47 p.m. UTC | #2
On 27.11.2016 04:07, Michael Niedermayer wrote:
> On Sat, Nov 26, 2016 at 11:36:48PM +0100, Andreas Cadhalpun wrote:
>>  pngdec.c |    3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>> 141d5230c97dbc47e0b291f660544cfe57abbf7c  0001-pngdec-check-if-previous-frame-exists-instead-of-tru.patch
>> From 84125e5f32fd4b9146d9926d2f8a4467da7c8557 Mon Sep 17 00:00:00 2001
>> From: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
>> Date: Fri, 25 Nov 2016 22:09:51 +0100
>> Subject: [PATCH] pngdec: check if previous frame exists instead of trusting
>>  sequence_number
>>
>> This fixes a segmentation fault caused by calling memcpy with NULL as
>> second argument in handle_p_frame_apng.
>>
>> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
>> ---
>>  libavcodec/pngdec.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> LGTM

Pushed.

Best regards,
Andreas
diff mbox

Patch

From 84125e5f32fd4b9146d9926d2f8a4467da7c8557 Mon Sep 17 00:00:00 2001
From: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Date: Fri, 25 Nov 2016 22:09:51 +0100
Subject: [PATCH] pngdec: check if previous frame exists instead of trusting
 sequence_number

This fixes a segmentation fault caused by calling memcpy with NULL as
second argument in handle_p_frame_apng.

Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
---
 libavcodec/pngdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 36275ae..2f8d266 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -922,7 +922,8 @@  static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s,
         return AVERROR_INVALIDDATA;
     }
 
-    if (sequence_number == 0 && dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
+    if ((sequence_number == 0 || !s->previous_picture.f->data[0]) &&
+        dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
         // No previous frame to revert to for the first frame
         // Spec says to just treat it as a APNG_DISPOSE_OP_BACKGROUND
         dispose_op = APNG_DISPOSE_OP_BACKGROUND;
-- 
2.10.2