diff mbox series

[FFmpeg-devel,08/14] avcodec/ffv1dec: Check allocations for failure

Message ID HE1PR0301MB2154526CB5F70898762378788F449@HE1PR0301MB2154.eurprd03.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,01/14] avcodec/ffv1dec: Remove redundant writes, fix races
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt April 24, 2021, 11:14 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/ffv1dec.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Michael Niedermayer April 25, 2021, 12:28 p.m. UTC | #1
On Sat, Apr 24, 2021 at 01:14:40PM +0200, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/ffv1dec.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)

LGTM assuming the error path was tested

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 45bfe21be5..791dc073bf 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -259,9 +259,17 @@  static int decode_slice(AVCodecContext *c, void *arg)
 
             if (fssrc->ac) {
                 pdst->state = av_malloc_array(CONTEXT_SIZE,  psrc->context_count);
+                if (!pdst->state) {
+                    ret = AVERROR(ENOMEM);
+                    goto fail;
+                }
                 memcpy(pdst->state, psrc->state, CONTEXT_SIZE * psrc->context_count);
             } else {
                 pdst->vlc_state = av_malloc_array(sizeof(*pdst->vlc_state), psrc->context_count);
+                if (!pdst->vlc_state) {
+                    ret = AVERROR(ENOMEM);
+                    goto fail;
+                }
                 memcpy(pdst->vlc_state, psrc->vlc_state, sizeof(*pdst->vlc_state) * psrc->context_count);
             }
         }
@@ -343,6 +351,10 @@  static int decode_slice(AVCodecContext *c, void *arg)
     ff_thread_report_progress(&f->picture, si, 0);
 
     return 0;
+fail:
+    fs->slice_damaged = 1;
+    ff_thread_report_progress(&f->picture, si, 0);
+    return ret;
 }
 
 static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale)