diff mbox series

[FFmpeg-devel,1/2] avcodec/vp9: prevent null pointer use on init_frames() failure

Message ID cc6c9ed6c32e98d02bf0b65b900eb6f5d5c6512c.1586068235.git.pross@xvid.org
State Accepted
Headers show
Series [FFmpeg-devel,1/2] avcodec/vp9: prevent null pointer use on init_frames() failure
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Peter Ross April 5, 2020, 6:31 a.m. UTC
---
 libavcodec/vp9.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

James Almer April 5, 2020, 2:18 p.m. UTC | #1
On 4/5/2020 3:31 AM, Peter Ross wrote:
> ---
>  libavcodec/vp9.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
> index 7ee375d4d0..c125e22975 100644
> --- a/libavcodec/vp9.c
> +++ b/libavcodec/vp9.c
> @@ -1216,18 +1216,24 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx)
>      int i;
>  
>      for (i = 0; i < 3; i++) {
> +        if (s->s.frames[i].tf.f) {
>          if (s->s.frames[i].tf.f->buf[0])
>              vp9_frame_unref(avctx, &s->s.frames[i]);
>          av_frame_free(&s->s.frames[i].tf.f);
> +        }
>      }
>      av_buffer_pool_uninit(&s->frame_extradata_pool);
>      for (i = 0; i < 8; i++) {
> +        if (s->s.refs[i].f) {
>          if (s->s.refs[i].f->buf[0])
>              ff_thread_release_buffer(avctx, &s->s.refs[i]);
>          av_frame_free(&s->s.refs[i].f);
> +        }
> +        if (s->next_refs[i].f) {
>          if (s->next_refs[i].f->buf[0])
>              ff_thread_release_buffer(avctx, &s->next_refs[i]);
>          av_frame_free(&s->next_refs[i].f);
> +        }
>      }

ff_thread_release_buffer() (and by extension vp9_frame_unref()) already
does a check for ThreadFrame->f then ThreadFrame->f->buf[0], so this can
be simplified into simply removing the existing checks here and call
ff_thread_release_buffer/vp9_frame_unref unconditionally.

See vp9_decode_flush().

>  
>      free_buffers(s);
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
Peter Ross April 7, 2020, 12:24 p.m. UTC | #2
Signed-off-by: Peter Ross <pross@xvid.org>
Reviewed-by: James Almer <jamrial@gmail.com>
---
 libavcodec/vp9.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 7ee375d4d0..2e6cd912a5 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -1216,17 +1216,14 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx)
     int i;
 
     for (i = 0; i < 3; i++) {
-        if (s->s.frames[i].tf.f->buf[0])
-            vp9_frame_unref(avctx, &s->s.frames[i]);
+        vp9_frame_unref(avctx, &s->s.frames[i]);
         av_frame_free(&s->s.frames[i].tf.f);
     }
     av_buffer_pool_uninit(&s->frame_extradata_pool);
     for (i = 0; i < 8; i++) {
-        if (s->s.refs[i].f->buf[0])
-            ff_thread_release_buffer(avctx, &s->s.refs[i]);
+        ff_thread_release_buffer(avctx, &s->s.refs[i]);
         av_frame_free(&s->s.refs[i].f);
-        if (s->next_refs[i].f->buf[0])
-            ff_thread_release_buffer(avctx, &s->next_refs[i]);
+        ff_thread_release_buffer(avctx, &s->next_refs[i]);
         av_frame_free(&s->next_refs[i].f);
     }
diff mbox series

Patch

diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 7ee375d4d0..c125e22975 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -1216,18 +1216,24 @@  static av_cold int vp9_decode_free(AVCodecContext *avctx)
     int i;
 
     for (i = 0; i < 3; i++) {
+        if (s->s.frames[i].tf.f) {
         if (s->s.frames[i].tf.f->buf[0])
             vp9_frame_unref(avctx, &s->s.frames[i]);
         av_frame_free(&s->s.frames[i].tf.f);
+        }
     }
     av_buffer_pool_uninit(&s->frame_extradata_pool);
     for (i = 0; i < 8; i++) {
+        if (s->s.refs[i].f) {
         if (s->s.refs[i].f->buf[0])
             ff_thread_release_buffer(avctx, &s->s.refs[i]);
         av_frame_free(&s->s.refs[i].f);
+        }
+        if (s->next_refs[i].f) {
         if (s->next_refs[i].f->buf[0])
             ff_thread_release_buffer(avctx, &s->next_refs[i]);
         av_frame_free(&s->next_refs[i].f);
+        }
     }
 
     free_buffers(s);