diff mbox

[FFmpeg-devel,3/4] avcodec/cook: Check samples_per_channel earlier

Message ID 20191023185714.2412-3-michael@niedermayer.cc
State Accepted
Commit 57750bb629a145326e20b8760f21f1041464a937
Headers show

Commit Message

Michael Niedermayer Oct. 23, 2019, 6:57 p.m. UTC
Fixes: division by zero
Fixes: 18362/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_COOK_fuzzer-5653727679086592

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/cook.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

Comments

Michael Niedermayer Nov. 9, 2019, 4:55 p.m. UTC | #1
On Wed, Oct 23, 2019 at 08:57:13PM +0200, Michael Niedermayer wrote:
> Fixes: division by zero
> Fixes: 18362/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_COOK_fuzzer-5653727679086592
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/cook.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)

will apply

[...]
diff mbox

Patch

diff --git a/libavcodec/cook.c b/libavcodec/cook.c
index aa11205166..3a40ccaf2c 100644
--- a/libavcodec/cook.c
+++ b/libavcodec/cook.c
@@ -1217,6 +1217,15 @@  static av_cold int cook_decode_init(AVCodecContext *avctx)
             return AVERROR_PATCHWELCOME;
         }
     }
+
+    /* Try to catch some obviously faulty streams, otherwise it might be exploitable */
+    if (q->samples_per_channel != 256 && q->samples_per_channel != 512 &&
+        q->samples_per_channel != 1024) {
+        avpriv_request_sample(avctx, "samples_per_channel = %d",
+                              q->samples_per_channel);
+        return AVERROR_PATCHWELCOME;
+    }
+
     /* Generate tables */
     init_pow2table();
     init_gain_table(q);
@@ -1252,14 +1261,6 @@  static av_cold int cook_decode_init(AVCodecContext *avctx)
         q->saturate_output = saturate_output_float;
     }
 
-    /* Try to catch some obviously faulty streams, otherwise it might be exploitable */
-    if (q->samples_per_channel != 256 && q->samples_per_channel != 512 &&
-        q->samples_per_channel != 1024) {
-        avpriv_request_sample(avctx, "samples_per_channel = %d",
-                              q->samples_per_channel);
-        return AVERROR_PATCHWELCOME;
-    }
-
     avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
     if (channel_mask)
         avctx->channel_layout = channel_mask;