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

Fixes: heap-buffer-overflow
Fixes: BiaeRPmt9wwq
Found-by: Hongduo Zhao


>From e37a385eea148646154d079791a330949c5b205c Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Tue, 29 Sep 2026 00:56:10 +0200
Subject: [PATCH 1/4] avfilter/af_arnndn: require the model layers to fit the
 network compute_rnn() runs

Reject a model whose layer sizes do not follow these relations. All
published rnnoise-nu models follow them.

The fix suggested in the report bounded the vad_output and
denoise_output inputs by the aligned state allocations instead.

Fixes: heap-buffer-overflow
Fixes: BiaeRPmt9wwq
Found-by: Hongduo Zhao
---
 libavfilter/af_arnndn.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavfilter/af_arnndn.c b/libavfilter/af_arnndn.c
index 6209f1b0e0..7277a7258c 100644
--- a/libavfilter/af_arnndn.c
+++ b/libavfilter/af_arnndn.c
@@ -317,7 +317,14 @@ static int rnnoise_model_from_file(FILE *f, RNNModel **rnn)
     INPUT_DENSE(denoise_output);
     INPUT_DENSE(vad_output);
 
-    if (vad_output->nb_neurons != 1) {
+    if (input_dense->nb_inputs    != NB_FEATURES ||
+        vad_gru->nb_inputs        != input_dense->nb_neurons ||
+        noise_gru->nb_inputs      != input_dense->nb_neurons + 
vad_gru->nb_neurons + NB_FEATURES ||
+        denoise_gru->nb_inputs    != vad_gru->nb_neurons + 
noise_gru->nb_neurons + NB_FEATURES ||
+        denoise_output->nb_inputs != denoise_gru->nb_neurons ||
+        denoise_output->nb_neurons != NB_BANDS ||
+        vad_output->nb_inputs     != vad_gru->nb_neurons ||
+        vad_output->nb_neurons    != 1) {
         rnnoise_model_free(ret);
         return AVERROR(EINVAL);
     }
-- 
2.52.0


>From 5f3314b26efe5332da5e4db3a98ee951cee99284 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Tue, 29 Sep 2026 01:25:17 +0200
Subject: [PATCH 2/4] avfilter/af_arnndn: reject model layers without inputs or
 neurons

Fixes: out of array access
Found during review of the security fix for BiaeRPmt9wwq
Replicated through UnModified FFmpeg
---
 libavfilter/af_arnndn.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavfilter/af_arnndn.c b/libavfilter/af_arnndn.c
index 7277a7258c..4ead29b31d 100644
--- a/libavfilter/af_arnndn.c
+++ b/libavfilter/af_arnndn.c
@@ -217,8 +217,8 @@ static int rnnoise_model_from_file(FILE *f, RNNModel **rnn)
     ALLOC_LAYER(DenseLayer, denoise_output);
     ALLOC_LAYER(DenseLayer, vad_output);
 
-#define INPUT_VAL(name) do { \
-    if (fscanf(f, "%d", &in) != 1 || in < 0 || in > 128) { \
+#define INPUT_VAL(name, min) do { \
+    if (fscanf(f, "%d", &in) != 1 || in < (min) || in > 128) { \
         rnnoise_model_free(ret); \
         return AVERROR(EINVAL); \
     } \
@@ -227,7 +227,7 @@ static int rnnoise_model_from_file(FILE *f, RNNModel **rnn)
 
 #define INPUT_ACTIVATION(name) do { \
     int activation; \
-    INPUT_VAL(activation); \
+    INPUT_VAL(activation, 0); \
     switch (activation) { \
     case F_ACTIVATION_SIGMOID: \
         name = ACTIVATION_SIGMOID; \
@@ -285,8 +285,8 @@ static int rnnoise_model_from_file(FILE *f, RNNModel **rnn)
     } while (0)
 
 #define INPUT_DENSE(name) do { \
-    INPUT_VAL(name->nb_inputs); \
-    INPUT_VAL(name->nb_neurons); \
+    INPUT_VAL(name->nb_inputs, 1); \
+    INPUT_VAL(name->nb_neurons, 1); \
     ret->name ## _size = name->nb_neurons; \
     INPUT_ACTIVATION(name->activation); \
     NEW_LINE(); \
@@ -297,8 +297,8 @@ static int rnnoise_model_from_file(FILE *f, RNNModel **rnn)
     } while (0)
 
 #define INPUT_GRU(name) do { \
-    INPUT_VAL(name->nb_inputs); \
-    INPUT_VAL(name->nb_neurons); \
+    INPUT_VAL(name->nb_inputs, 1); \
+    INPUT_VAL(name->nb_neurons, 1); \
     ret->name ## _size = name->nb_neurons; \
     INPUT_ACTIVATION(name->activation); \
     NEW_LINE(); \
-- 
2.52.0


>From b44bdbe7bbeb9156ff54bb5f314e112133970d02 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Tue, 29 Sep 2026 01:25:17 +0200
Subject: [PATCH 3/4] cosmetics: avfilter/af_arnndn: use NB_FEATURES for the
 size of the feature vector

INPUT_SIZE was a second name for the same 42 element feature vector
that NB_FEATURES describes.
---
 libavfilter/af_arnndn.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libavfilter/af_arnndn.c b/libavfilter/af_arnndn.c
index 4ead29b31d..bc9fc3ad11 100644
--- a/libavfilter/af_arnndn.c
+++ b/libavfilter/af_arnndn.c
@@ -1336,8 +1336,6 @@ static void compute_gru(AudioRNNContext *s, const 
GRULayer *gru, float *state, c
     RNN_COPY(state, h, N);
 }
 
-#define INPUT_SIZE 42
-
 static void compute_rnn(AudioRNNContext *s, RNNState *rnn, float *gains, float 
*vad, const float *input)
 {
     LOCAL_ALIGNED_32(float, dense_out,     [MAX_NEURONS]);
@@ -1352,7 +1350,7 @@ static void compute_rnn(AudioRNNContext *s, RNNState 
*rnn, float *gains, float *
     memcpy(noise_input + rnn->model->input_dense_size,
            rnn->vad_gru_state, rnn->model->vad_gru_size * sizeof(float));
     memcpy(noise_input + rnn->model->input_dense_size + 
rnn->model->vad_gru_size,
-           input, INPUT_SIZE * sizeof(float));
+           input, NB_FEATURES * sizeof(float));
 
     compute_gru(s, rnn->model->noise_gru, rnn->noise_gru_state, noise_input);
 
@@ -1360,7 +1358,7 @@ static void compute_rnn(AudioRNNContext *s, RNNState 
*rnn, float *gains, float *
     memcpy(denoise_input + rnn->model->vad_gru_size,
            rnn->noise_gru_state, rnn->model->noise_gru_size * sizeof(float));
     memcpy(denoise_input + rnn->model->vad_gru_size + 
rnn->model->noise_gru_size,
-           input, INPUT_SIZE * sizeof(float));
+           input, NB_FEATURES * sizeof(float));
 
     compute_gru(s, rnn->model->denoise_gru, rnn->denoise_gru_state, 
denoise_input);
     compute_dense(rnn->model->denoise_output, gains, rnn->denoise_gru_state);
-- 
2.52.0


>From 8e848d355e46cb0768003b11eb49d4bd44fadd44 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Tue, 29 Sep 2026 01:25:17 +0200
Subject: [PATCH 4/4] avfilter/af_arnndn: zero the GRU input vectors before
 filling them

Fixes: use of uninitialized memory
Found during review of the security fix for BiaeRPmt9wwq
Replicated through UnModified FFmpeg
---
 libavfilter/af_arnndn.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavfilter/af_arnndn.c b/libavfilter/af_arnndn.c
index bc9fc3ad11..dd51a83e7f 100644
--- a/libavfilter/af_arnndn.c
+++ b/libavfilter/af_arnndn.c
@@ -1342,6 +1342,9 @@ static void compute_rnn(AudioRNNContext *s, RNNState 
*rnn, float *gains, float *
     LOCAL_ALIGNED_32(float, noise_input,   [MAX_NEURONS * 3]);
     LOCAL_ALIGNED_32(float, denoise_input, [MAX_NEURONS * 3]);
 
+    memset(dense_out,     0, MAX_NEURONS     * sizeof(float));
+    memset(noise_input,   0, MAX_NEURONS * 3 * sizeof(float));
+    memset(denoise_input, 0, MAX_NEURONS * 3 * sizeof(float));
     compute_dense(rnn->model->input_dense, dense_out, input);
     compute_gru(s, rnn->model->vad_gru, rnn->vad_gru_state, dense_out);
     compute_dense(rnn->model->vad_output, vad, rnn->vad_gru_state);
-- 
2.52.0

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

Reply via email to