diff mbox series

[FFmpeg-devel,2/9] avcodec/mpeg4audio: Check that there is enough space for the first 3 elements in ff_mpeg4audio_get_config_gb()

Message ID 20240616230831.912377-2-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/9] avcodec/targaenc: Allocate space for the palette | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Michael Niedermayer June 16, 2024, 11:08 p.m. UTC
Fixes: out of array access
Fixes: 68863/clusterfuzz-testcase-minimized-ffmpeg_dem_IAMF_fuzzer-4833546039525376

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

Comments

Andreas Rheinhardt June 17, 2024, 5:27 a.m. UTC | #1
Michael Niedermayer:
> Fixes: out of array access
> Fixes: 68863/clusterfuzz-testcase-minimized-ffmpeg_dem_IAMF_fuzzer-4833546039525376
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/mpeg4audio.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavcodec/mpeg4audio.c b/libavcodec/mpeg4audio.c
> index fbd2a8f811a..ae18944f0d5 100644
> --- a/libavcodec/mpeg4audio.c
> +++ b/libavcodec/mpeg4audio.c
> @@ -94,6 +94,10 @@ int ff_mpeg4audio_get_config_gb(MPEG4AudioConfig *c, GetBitContext *gb,
>  {
>      int specific_config_bitindex, ret;
>      int start_bit_index = get_bits_count(gb);
> +
> +    if (get_bits_left(gb) < 5+4+4)
> +        return AVERROR_INVALIDDATA;
> +
>      c->object_type = get_object_type(gb);
>      c->sample_rate = get_sample_rate(gb, &c->sampling_index);
>      c->chan_config = get_bits(gb, 4);

This is not a proper fix. The real bug seems to be that
avpriv_mpeg4audio_get_config2() relies on the buffer to be padded, but
iamf_parse.c does not add padding.

- Andreas
Michael Niedermayer June 18, 2024, 10 p.m. UTC | #2
On Mon, Jun 17, 2024 at 07:27:16AM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Fixes: out of array access
> > Fixes: 68863/clusterfuzz-testcase-minimized-ffmpeg_dem_IAMF_fuzzer-4833546039525376
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/mpeg4audio.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/libavcodec/mpeg4audio.c b/libavcodec/mpeg4audio.c
> > index fbd2a8f811a..ae18944f0d5 100644
> > --- a/libavcodec/mpeg4audio.c
> > +++ b/libavcodec/mpeg4audio.c
> > @@ -94,6 +94,10 @@ int ff_mpeg4audio_get_config_gb(MPEG4AudioConfig *c, GetBitContext *gb,
> >  {
> >      int specific_config_bitindex, ret;
> >      int start_bit_index = get_bits_count(gb);
> > +
> > +    if (get_bits_left(gb) < 5+4+4)
> > +        return AVERROR_INVALIDDATA;
> > +
> >      c->object_type = get_object_type(gb);
> >      c->sample_rate = get_sample_rate(gb, &c->sampling_index);
> >      c->chan_config = get_bits(gb, 4);
> 
> This is not a proper fix. The real bug seems to be that
> avpriv_mpeg4audio_get_config2() relies on the buffer to be padded, but
> iamf_parse.c does not add padding.

indeed, patch droped

james already posted a better fix

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/mpeg4audio.c b/libavcodec/mpeg4audio.c
index fbd2a8f811a..ae18944f0d5 100644
--- a/libavcodec/mpeg4audio.c
+++ b/libavcodec/mpeg4audio.c
@@ -94,6 +94,10 @@  int ff_mpeg4audio_get_config_gb(MPEG4AudioConfig *c, GetBitContext *gb,
 {
     int specific_config_bitindex, ret;
     int start_bit_index = get_bits_count(gb);
+
+    if (get_bits_left(gb) < 5+4+4)
+        return AVERROR_INVALIDDATA;
+
     c->object_type = get_object_type(gb);
     c->sample_rate = get_sample_rate(gb, &c->sampling_index);
     c->chan_config = get_bits(gb, 4);