PR #24420 opened by Forgejo_Fairy
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24420
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24420.patch

Backport upstream fix 2d9ed64859c to release/6.1.

The final input frame passed to `de_stereo()` can contain fewer samples than 
the configured overlap. The old code nevertheless copied the full overlap from 
both input planes, causing a heap-buffer-overflow. Limit the copies to the 
number of samples actually available and carry over the upstream 
temporary-buffer allocation adjustment.

Fixes #22762.

The change matches the patch submitted by lizhixuan.HUST and retains their 
authorship.

Verification:

- Reproduced the ASan heap-buffer-overflow on release/6.1 at f22d56bd5ca with 
the issue's PoC.
- Confirmed the same command exits successfully without an ASan finding after 
this patch.
- Passed `fate-ffmpeg-filter_complex_audio`.
- Passed `fate-ffmpeg-lavfi`.


>From 53749d63e9a7e63a93844f2b7265704f58e2666b Mon Sep 17 00:00:00 2001
From: "lizhixuan.HUST" <[email protected]>
Date: Mon, 7 Sep 2026 22:12:12 +0000
Subject: [PATCH] avfilter/af_dialoguenhance: fix overreads

Backport of 2d9ed64859c9887d0504cd71dbd5b2c15e14251a to release/6.1.

Fixes: #22762

Signed-off-by: lizhixuan.HUST <[email protected]>

Assisted-by: Fairy
---
 libavfilter/af_dialoguenhance.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavfilter/af_dialoguenhance.c b/libavfilter/af_dialoguenhance.c
index 1762ea7cde..29c8ab10a7 100644
--- a/libavfilter/af_dialoguenhance.c
+++ b/libavfilter/af_dialoguenhance.c
@@ -96,12 +96,12 @@ static int config_input(AVFilterLink *inlink)
     if (!s->window)
         return AVERROR(ENOMEM);
 
-    s->in_frame       = ff_get_audio_buffer(inlink, s->fft_size * 4);
-    s->center_frame   = ff_get_audio_buffer(inlink, s->fft_size * 4);
-    s->out_dist_frame = ff_get_audio_buffer(inlink, s->fft_size * 4);
-    s->windowed_frame = ff_get_audio_buffer(inlink, s->fft_size * 4);
-    s->windowed_out   = ff_get_audio_buffer(inlink, s->fft_size * 4);
-    s->windowed_prev  = ff_get_audio_buffer(inlink, s->fft_size * 4);
+    s->in_frame       = ff_get_audio_buffer(inlink, (s->fft_size + 2) * 2);
+    s->center_frame   = ff_get_audio_buffer(inlink, (s->fft_size + 2) * 2);
+    s->out_dist_frame = ff_get_audio_buffer(inlink, (s->fft_size + 2) * 2);
+    s->windowed_frame = ff_get_audio_buffer(inlink, (s->fft_size + 2) * 2);
+    s->windowed_out   = ff_get_audio_buffer(inlink, (s->fft_size + 2) * 2);
+    s->windowed_prev  = ff_get_audio_buffer(inlink, (s->fft_size + 2) * 2);
     if (!s->in_frame || !s->windowed_out || !s->windowed_prev ||
         !s->out_dist_frame || !s->windowed_frame || !s->center_frame)
         return AVERROR(ENOMEM);
@@ -250,6 +250,7 @@ static int de_stereo(AVFilterContext *ctx, AVFrame *out)
     float *right_osamples  = (float *)out->extended_data[1];
     float *center_osamples = (float *)out->extended_data[2];
     const int offset = s->fft_size - s->overlap;
+    const int nb_samples = FFMIN(s->overlap, s->in->nb_samples);
     float vad;
 
     // shift in/out buffers
@@ -258,8 +259,8 @@ static int de_stereo(AVFilterContext *ctx, AVFrame *out)
     memmove(left_out, &left_out[s->overlap], offset * sizeof(float));
     memmove(right_out, &right_out[s->overlap], offset * sizeof(float));
 
-    memcpy(&left_in[offset], left_samples, s->overlap * sizeof(float));
-    memcpy(&right_in[offset], right_samples, s->overlap * sizeof(float));
+    memcpy(&left_in[offset], left_samples, nb_samples * sizeof(float));
+    memcpy(&right_in[offset], right_samples, nb_samples * sizeof(float));
     memset(&left_out[offset], 0, s->overlap * sizeof(float));
     memset(&right_out[offset], 0, s->overlap * sizeof(float));
 
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to