aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2020-01-15 00:32:55 +0100
committerMichael Niedermayer <michael@niedermayer.cc>2020-07-03 12:10:23 +0200
commit623ecb2ec855fbf0cf5e75928d063a07aa705e3f (patch)
tree96ba1628f2c33f0edd4685cd3317b73b4e9c38d7
parent94a1280fb0b1a1cf34c7f28d2c2d2e42c42840b3 (diff)
downloadffmpeg-623ecb2ec855fbf0cf5e75928d063a07aa705e3f.tar.gz
avcodec/wmalosslessdec: move channel check up
Fixes: out of array access Fixes: 2nd part of 18429/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WMALOSSLESS_fuzzer-6210814364614656 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit 891bcc4acc93e0c5a75ab7a9da668df84a0edba7) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r--libavcodec/wmalosslessdec.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c
index d47fd89c52..220488df3c 100644
--- a/libavcodec/wmalosslessdec.c
+++ b/libavcodec/wmalosslessdec.c
@@ -189,6 +189,16 @@ static av_cold int decode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
+ if (avctx->channels < 0) {
+ av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n",
+ avctx->channels);
+ return AVERROR_INVALIDDATA;
+ } else if (avctx->channels > WMALL_MAX_CHANNELS) {
+ avpriv_request_sample(avctx,
+ "More than %d channels", WMALL_MAX_CHANNELS);
+ return AVERROR_PATCHWELCOME;
+ }
+
s->max_frame_size = MAX_FRAMESIZE * avctx->channels;
s->frame_data = av_mallocz(s->max_frame_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!s->frame_data)
@@ -267,16 +277,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
++s->lfe_channel;
}
- if (s->num_channels < 0) {
- av_log(avctx, AV_LOG_ERROR, "invalid number of channels %"PRId8"\n",
- s->num_channels);
- return AVERROR_INVALIDDATA;
- } else if (s->num_channels > WMALL_MAX_CHANNELS) {
- avpriv_request_sample(avctx,
- "More than %d channels", WMALL_MAX_CHANNELS);
- return AVERROR_PATCHWELCOME;
- }
-
s->frame = av_frame_alloc();
if (!s->frame)
return AVERROR(ENOMEM);