diff mbox series

[FFmpeg-devel] avcodec/siren: Check several indexes

Message ID 20200229234837.14142-1-michael@niedermayer.cc
State Accepted
Headers show
Series [FFmpeg-devel] avcodec/siren: Check several indexes
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Michael Niedermayer Feb. 29, 2020, 11:48 p.m. UTC
Fixes: Multiple out of array accesses
Fixes: 20817/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SIREN_fuzzer-5754041227542528.fuzz

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/siren.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Comments

Paul B Mahol March 4, 2020, 3:59 p.m. UTC | #1
lgtm

On 3/1/20, Michael Niedermayer <michael@niedermayer.cc> wrote:
> Fixes: Multiple out of array accesses
> Fixes:
> 20817/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SIREN_fuzzer-5754041227542528.fuzz
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/siren.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/libavcodec/siren.c b/libavcodec/siren.c
> index 2577ff52dd..76dfe62843 100644
> --- a/libavcodec/siren.c
> +++ b/libavcodec/siren.c
> @@ -428,6 +428,7 @@ static int decode_envelope(SirenContext *s,
> GetBitContext *gb,
>                             int *absolute_region_power_index, int
> esf_adjustment)
>  {
>      absolute_region_power_index[0] = (int)get_bits(gb, 5) - esf_adjustment;
> +    absolute_region_power_index[0] =
> av_clip(absolute_region_power_index[0], -24, 39);
>      decoder_standard_deviation[0] =
> s->standard_deviation[absolute_region_power_index[0] + 24];
>
>      for (int i = 1; i < number_of_regions; i++) {
> @@ -437,7 +438,7 @@ static int decode_envelope(SirenContext *s,
> GetBitContext *gb,
>              index = differential_decoder_tree[i - 1][index][get_bits1(gb)];
>          } while (index > 0);
>
> -        absolute_region_power_index[i] = absolute_region_power_index[i - 1]
> - index - 12;
> +        absolute_region_power_index[i] =
> av_clip(absolute_region_power_index[i - 1] - index - 12, -24, 39);
>          decoder_standard_deviation[i] =
> s->standard_deviation[absolute_region_power_index[i] + 24];
>      }
>
> @@ -500,6 +501,8 @@ static int categorize_regions(int number_of_regions, int
> number_of_available_bit
>                      }
>                  }
>              }
> +            if (raw_value == -99)
> +                return AVERROR_INVALIDDATA;
>              *min_rate_ptr++ = raw_min_idx;
>              min +=
>                  expected_bits_table[min_rate_categories[raw_min_idx] + 1] -
> @@ -518,6 +521,8 @@ static int categorize_regions(int number_of_regions, int
> number_of_available_bit
>                      }
>                  }
>              }
> +            if (raw_value == 99)
> +                return AVERROR_INVALIDDATA;
>
>              *--max_rate_ptr = raw_max_idx;
>              max += expected_bits_table[max_rate_categories[raw_max_idx] -
> 1] -
> @@ -684,9 +689,11 @@ static int siren_decode(AVCodecContext *avctx, void
> *data,
>
>      rate_control = get_bits(gb, 4);
>
> -    categorize_regions(s->number_of_regions, get_bits_left(gb),
> -                       s->absolute_region_power_index, s->power_categories,
> -                       s->category_balance);
> +    ret = categorize_regions(s->number_of_regions, get_bits_left(gb),
> +                             s->absolute_region_power_index,
> s->power_categories,
> +                             s->category_balance);
> +    if (ret < 0)
> +        return ret;
>
>      for (int i = 0; i < rate_control; i++)
>          s->power_categories[s->category_balance[i]]++;
> --
> 2.17.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Michael Niedermayer March 4, 2020, 10:22 p.m. UTC | #2
On Wed, Mar 04, 2020 at 04:59:10PM +0100, Paul B Mahol wrote:
> lgtm

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/siren.c b/libavcodec/siren.c
index 2577ff52dd..76dfe62843 100644
--- a/libavcodec/siren.c
+++ b/libavcodec/siren.c
@@ -428,6 +428,7 @@  static int decode_envelope(SirenContext *s, GetBitContext *gb,
                            int *absolute_region_power_index, int esf_adjustment)
 {
     absolute_region_power_index[0] = (int)get_bits(gb, 5) - esf_adjustment;
+    absolute_region_power_index[0] = av_clip(absolute_region_power_index[0], -24, 39);
     decoder_standard_deviation[0] = s->standard_deviation[absolute_region_power_index[0] + 24];
 
     for (int i = 1; i < number_of_regions; i++) {
@@ -437,7 +438,7 @@  static int decode_envelope(SirenContext *s, GetBitContext *gb,
             index = differential_decoder_tree[i - 1][index][get_bits1(gb)];
         } while (index > 0);
 
-        absolute_region_power_index[i] = absolute_region_power_index[i - 1] - index - 12;
+        absolute_region_power_index[i] = av_clip(absolute_region_power_index[i - 1] - index - 12, -24, 39);
         decoder_standard_deviation[i] = s->standard_deviation[absolute_region_power_index[i] + 24];
     }
 
@@ -500,6 +501,8 @@  static int categorize_regions(int number_of_regions, int number_of_available_bit
                     }
                 }
             }
+            if (raw_value == -99)
+                return AVERROR_INVALIDDATA;
             *min_rate_ptr++ = raw_min_idx;
             min +=
                 expected_bits_table[min_rate_categories[raw_min_idx] + 1] -
@@ -518,6 +521,8 @@  static int categorize_regions(int number_of_regions, int number_of_available_bit
                     }
                 }
             }
+            if (raw_value == 99)
+                return AVERROR_INVALIDDATA;
 
             *--max_rate_ptr = raw_max_idx;
             max += expected_bits_table[max_rate_categories[raw_max_idx] - 1] -
@@ -684,9 +689,11 @@  static int siren_decode(AVCodecContext *avctx, void *data,
 
     rate_control = get_bits(gb, 4);
 
-    categorize_regions(s->number_of_regions, get_bits_left(gb),
-                       s->absolute_region_power_index, s->power_categories,
-                       s->category_balance);
+    ret = categorize_regions(s->number_of_regions, get_bits_left(gb),
+                             s->absolute_region_power_index, s->power_categories,
+                             s->category_balance);
+    if (ret < 0)
+        return ret;
 
     for (int i = 0; i < rate_control; i++)
         s->power_categories[s->category_balance[i]]++;