diff mbox series

[FFmpeg-devel,1/5] avcodec/pngdec: Check last AVFrame before deref

Message ID 20240426235211.3718252-1-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/5] avcodec/pngdec: Check last AVFrame before deref | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Michael Niedermayer April 26, 2024, 11:52 p.m. UTC
Fixes: NULL pointer dereference
Fixes: 68184/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APNG_fuzzer-4926478069334016

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/pngdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andreas Rheinhardt April 27, 2024, 9:36 a.m. UTC | #1
Michael Niedermayer:
> Fixes: NULL pointer dereference
> Fixes: 68184/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APNG_fuzzer-4926478069334016
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/pngdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
> index f7751223b81..b24bfa248dc 100644
> --- a/libavcodec/pngdec.c
> +++ b/libavcodec/pngdec.c
> @@ -1218,7 +1218,7 @@ static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s,
>          return AVERROR_INVALIDDATA;
>      }
>  
> -    if ((sequence_number == 0 || !s->last_picture.f->data[0]) &&
> +    if ((sequence_number == 0 || !s->last_picture.f || !s->last_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

Just checking for !s->last_picture.f is enough -- s->last_picture.f is
set if and only if s->last_picture.f->data[0] is set.

- Andreas
Michael Niedermayer April 27, 2024, 6:13 p.m. UTC | #2
On Sat, Apr 27, 2024 at 11:36:30AM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Fixes: NULL pointer dereference
> > Fixes: 68184/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APNG_fuzzer-4926478069334016
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/pngdec.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
> > index f7751223b81..b24bfa248dc 100644
> > --- a/libavcodec/pngdec.c
> > +++ b/libavcodec/pngdec.c
> > @@ -1218,7 +1218,7 @@ static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s,
> >          return AVERROR_INVALIDDATA;
> >      }
> >  
> > -    if ((sequence_number == 0 || !s->last_picture.f->data[0]) &&
> > +    if ((sequence_number == 0 || !s->last_picture.f || !s->last_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
> 
> Just checking for !s->last_picture.f is enough -- s->last_picture.f is
> set if and only if s->last_picture.f->data[0] is set.

ok will apply with that simplified

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index f7751223b81..b24bfa248dc 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -1218,7 +1218,7 @@  static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s,
         return AVERROR_INVALIDDATA;
     }
 
-    if ((sequence_number == 0 || !s->last_picture.f->data[0]) &&
+    if ((sequence_number == 0 || !s->last_picture.f || !s->last_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