diff mbox series

[FFmpeg-devel,4/4] avcodec/xpmdec: Move allocations down after more error checks

Message ID 20210903183913.15255-4-michael@niedermayer.cc
State Accepted
Commit e58692837c20c8484a23cd9beb63ac422f82458a
Headers show
Series [FFmpeg-devel,1/4] avcodec/utils: ARGO writes 4x4 blocks without regard to the image dimensions | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Michael Niedermayer Sept. 3, 2021, 6:39 p.m. UTC
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
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/xpmdec.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Paul B Mahol Sept. 3, 2021, 6:51 p.m. UTC | #1
probably fine
Michael Niedermayer Sept. 5, 2021, 8:26 p.m. UTC | #2
On Fri, Sep 03, 2021 at 08:51:23PM +0200, Paul B Mahol wrote:
> probably fine

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/xpmdec.c b/libavcodec/xpmdec.c
index e609a70c6a..a11926ba28 100644
--- a/libavcodec/xpmdec.c
+++ b/libavcodec/xpmdec.c
@@ -341,9 +341,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;
@@ -360,14 +357,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;