]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/bgmc: Check input space in ff_bgmc_decode_init()
authorMichael Niedermayer <michael@niedermayer.cc>
Sun, 1 Sep 2019 20:31:45 +0000 (22:31 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Mon, 2 Sep 2019 16:09:11 +0000 (18:09 +0200)
Fixes: Infinite loop
Fixes: 16608/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ALS_fuzzer-5636229827133440
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Thilo Borgmann <thilo.borgmann@mail.de>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/alsdec.c
libavcodec/bgmc.c
libavcodec/bgmc.h

index 11bbd38f582aaf2dae9f37b2d37fe38e9ddaf9f3..f8d10df8c6c06103e3ee05d038f44998d4b2ffa7 100644 (file)
@@ -821,7 +821,9 @@ static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd)
         unsigned int low;
         unsigned int value;
 
-        ff_bgmc_decode_init(gb, &high, &low, &value);
+        int ret = ff_bgmc_decode_init(gb, &high, &low, &value);
+        if (ret < 0)
+            return ret;
 
         current_res = bd->raw_samples + start;
 
index 1a6817b73f7b3fb895c40d9a24a3902f0513fcc2..2d59aa37adb35f1d1b14ac331682b15c1c46cd4b 100644 (file)
@@ -485,12 +485,17 @@ av_cold void ff_bgmc_end(uint8_t **cf_lut, int **cf_lut_status)
 
 
 /** Initialize decoding and reads the first value */
-void ff_bgmc_decode_init(GetBitContext *gb, unsigned int *h,
+int ff_bgmc_decode_init(GetBitContext *gb, unsigned int *h,
                          unsigned int *l, unsigned int *v)
 {
+    if (get_bits_left(gb) < VALUE_BITS)
+        return AVERROR_INVALIDDATA;
+
     *h = TOP_VALUE;
     *l = 0;
     *v = get_bits_long(gb, VALUE_BITS);
+
+    return 0;
 }
 
 
index 4893736af5a35694e1e1d2ea2a64f8804c10f51d..466df31a2e081ca91c016dfa44f9e607054f2352 100644 (file)
@@ -40,7 +40,7 @@ int ff_bgmc_init(AVCodecContext *avctx, uint8_t **cf_lut, int **cf_lut_status);
 void ff_bgmc_end(uint8_t **cf_lut, int **cf_lut_status);
 
 
-void ff_bgmc_decode_init(GetBitContext *gb,
+int ff_bgmc_decode_init(GetBitContext *gb,
                       unsigned int *h, unsigned int *l, unsigned int *v);