aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2021-09-03 18:54:08 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2021-09-09 13:59:05 +0200
commit29d6be42d1f4a79dbec05d0dee67bc7ef8d878e0 (patch)
treec2b172010e9eb4386979b783453b49d372bdc002
parentfeba3d29be7b0da1e4ae2fd65bb91616afaa51a3 (diff)
downloadffmpeg-29d6be42d1f4a79dbec05d0dee67bc7ef8d878e0.tar.gz
avcodec/xpmdec: Move allocations down after more error checks
Fixes: Timeout Fixes: 37035/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_XPM_fuzzer-5142718576721920 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit e58692837c20c8484a23cd9beb63ac422f82458a) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r--libavcodec/xpmdec.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/libavcodec/xpmdec.c b/libavcodec/xpmdec.c
index 82a484dabb..8aee89dd30 100644
--- a/libavcodec/xpmdec.c
+++ b/libavcodec/xpmdec.c
@@ -337,9 +337,6 @@ static int xpm_decode_frame(AVCodecContext *avctx, void *data,
if ((ret = ff_set_dimensions(avctx, width, height)) < 0)
return ret;
- if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
- return ret;
-
if (cpp <= 0 || cpp >= 5) {
av_log(avctx, AV_LOG_ERROR, "unsupported/invalid number of chars per pixel: %d\n", cpp);
return AVERROR_INVALIDDATA;
@@ -356,14 +353,17 @@ static int xpm_decode_frame(AVCodecContext *avctx, void *data,
size *= 4;
- av_fast_padded_malloc(&x->pixels, &x->pixels_size, size);
- if (!x->pixels)
- return AVERROR(ENOMEM);
-
ptr += mod_strcspn(ptr, ",") + 1;
if (end - ptr < 1)
return AVERROR_INVALIDDATA;
+ if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
+ return ret;
+
+ av_fast_padded_malloc(&x->pixels, &x->pixels_size, size);
+ if (!x->pixels)
+ return AVERROR(ENOMEM);
+
for (i = 0; i < ncolors; i++) {
const uint8_t *index;
int len;