aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2019-07-15 23:26:05 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2019-12-02 19:41:49 +0100
commit1d752c2a057d305752e74ab9f34df878b4882f75 (patch)
tree3acb16b1a59dd696d2982fc2f048cbed07806e9a
parent5a7b7fc0258f8d08a22017a57a7f094fbaf6b3c1 (diff)
downloadffmpeg-1d752c2a057d305752e74ab9f34df878b4882f75.tar.gz
avcodec/sanm: Check extradata_size before allocations
Fixes: Leaks Fixes: 15349/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SANM_fuzzer-5102530557640704 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit 172a43ce36e671fdab63afe1c06876bba91445b3) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r--libavcodec/sanm.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 065bf7aca1..432e703ee9 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -491,6 +491,11 @@ static av_cold int decode_init(AVCodecContext *avctx)
ctx->avctx = avctx;
ctx->version = !avctx->extradata_size;
+ // early sanity check before allocations to avoid need for deallocation code.
+ if (!ctx->version && avctx->extradata_size < 1026) {
+ av_log(avctx, AV_LOG_ERROR, "Not enough extradata.\n");
+ return AVERROR_INVALIDDATA;
+ }
avctx->pix_fmt = ctx->version ? AV_PIX_FMT_RGB565 : AV_PIX_FMT_PAL8;
@@ -506,11 +511,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
if (!ctx->version) {
int i;
- if (avctx->extradata_size < 1026) {
- av_log(avctx, AV_LOG_ERROR, "Not enough extradata.\n");
- return AVERROR_INVALIDDATA;
- }
-
ctx->subversion = AV_RL16(avctx->extradata);
for (i = 0; i < PALETTE_SIZE; i++)
ctx->pal[i] = 0xFFU << 24 | AV_RL32(avctx->extradata + 2 + i * 4);