diff mbox series

[FFmpeg-devel] Fix for possible buffer overflow.

Message ID 20220106004341.C06AC3F170@m2osw.com
State New
Headers show
Series [FFmpeg-devel] Fix for possible buffer overflow. | expand

Checks

Context Check Description
andriy/commit_msg_x86 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/make_x86 fail Make failed
andriy/commit_msg_ppc warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/make_ppc fail Make failed

Commit Message

AlexisWilke Jan. 6, 2022, 12:26 a.m. UTC
If it is true that the (index + c) can be larger than s->limiter_buf_size
then the overflow potential has to be handled in the previous two statements.

Signed-off-by: AlexisWilke <alexis@m2osw.com>
---
 libavfilter/af_loudnorm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Michael Niedermayer Jan. 6, 2022, 9:05 a.m. UTC | #1
On Wed, Jan 05, 2022 at 04:26:09PM -0800, AlexisWilke wrote:
> If it is true that the (index + c) can be larger than s->limiter_buf_size
> then the overflow potential has to be handled in the previous two statements.
> 
> Signed-off-by: AlexisWilke <alexis@m2osw.com>
> ---
>  libavfilter/af_loudnorm.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/libavfilter/af_loudnorm.c b/libavfilter/af_loudnorm.c
> index dbe7fba986..9e6a830a56 100644
> --- a/libavfilter/af_loudnorm.c
> +++ b/libavfilter/af_loudnorm.c
> @@ -206,10 +206,11 @@ static void detect_peak(LoudNormContext *s, int offset, int nb_samples, int chan
>                      continue;
>  
>                  for (c = 0; c < channels; c++) {
> -                    if (c == 0 || fabs(buf[index + c]) > max_peak)
> -                        max_peak = fabs(buf[index + c]);

> +                    int idx((index + c) < s->limiter_buf_size ? (index + c) : (index + c - s->limiter_buf_size));

which compiler did build this successfully ?


[...]
diff mbox series

Patch

diff --git a/libavfilter/af_loudnorm.c b/libavfilter/af_loudnorm.c
index dbe7fba986..9e6a830a56 100644
--- a/libavfilter/af_loudnorm.c
+++ b/libavfilter/af_loudnorm.c
@@ -206,10 +206,11 @@  static void detect_peak(LoudNormContext *s, int offset, int nb_samples, int chan
                     continue;
 
                 for (c = 0; c < channels; c++) {
-                    if (c == 0 || fabs(buf[index + c]) > max_peak)
-                        max_peak = fabs(buf[index + c]);
+                    int idx((index + c) < s->limiter_buf_size ? (index + c) : (index + c - s->limiter_buf_size));
+                    if (c == 0 || fabs(buf[idx]) > max_peak)
+                        max_peak = fabs(buf[idx]);
 
-                    s->prev_smp[c] = fabs(buf[(index + c) < s->limiter_buf_size ? (index + c) : (index + c - s->limiter_buf_size)]);
+                    s->prev_smp[c] = fabs(buf[idx]);
                 }
 
                 *peak_delta = n;