[FFmpeg-devel] [PATCH] Fix for possible buffer overflow.

AlexisWilke alexis at m2osw.com
Thu Jan 6 02:26:09 EET 2022


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 at 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));
+                    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;
-- 
2.17.1



More information about the ffmpeg-devel mailing list