PR #25597 opened by Marvin Scholz (ePirat)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25597
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25597.patch

Fix float cast overflow in wiener_denoise() / calc_input_response() due to a
cast of -NaN to integer.

Add boundary guards against zero or uniformly flat spectrum energies
in calc_input_response():
- In the log_range macro calculation, clamp the minimum energy input to
  1e-31f before passing it to log10f().
- In the irange calculation, guard against zero range.


>From 98b33d3b0167e3b510f1b89645ad3c734318c114 Mon Sep 17 00:00:00 2001
From: Marvin Scholz <[email protected]>
Date: Thu, 29 Oct 2026 22:10:07 +0000
Subject: [PATCH] avcodec/wmavoice: prevent float-cast-overflow on zero energy

Fix float cast overflow in wiener_denoise() / calc_input_response() due to a
cast of -NaN to integer.

Add boundary guards against zero or uniformly flat spectrum energies
in calc_input_response():
- In the log_range macro calculation, clamp the minimum energy input to
  1e-31f before passing it to log10f().
- In the irange calculation, guard against zero range.

Signed-off-by: Marvin Scholz <[email protected]>
---
 libavcodec/wmavoice.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c
index c3cd053ba9d..130dba7224b 100644
--- a/libavcodec/wmavoice.c
+++ b/libavcodec/wmavoice.c
@@ -622,7 +622,7 @@ static void calc_input_response(WMAVoiceContext *s, float 
*lpcs_src,
     /* Create frequency power spectrum of speech input (i.e. RDFT of LPCs) */
     s->rdft_fn(s->rdft, lpcs, lpcs_src, sizeof(float));
 #define log_range(var, assign) do { \
-        float tmp = log10f(assign);  var = tmp; \
+        float tmp = log10f(FFMAX(1e-31f, assign));  var = tmp; \
         max       = FFMAX(max, tmp); min = FFMIN(min, tmp); \
     } while (0)
     log_range(last_coeff,  lpcs[64]         * lpcs[64]);
@@ -639,7 +639,7 @@ static void calc_input_response(WMAVoiceContext *s, float 
*lpcs_src,
      * and set up a table (still in lpc[]) of (relative) gains per frequency.
      * These frequencies will be maintained, while others ("noise") will be
      * decreased in the filter output. */
-    irange    = 64.0 / range; // so irange*(max-value) is in the range [0, 63]
+    irange    = range > 0.0 ? 64.0 / range : 0.0; // so irange*(max-value) is 
in the range [0, 63]
     gain_mul  = range * (fcb_type == FCB_TYPE_HARDCODED ? (5.0 / 13.0) :
                                                           (5.0 / 14.7));
     angle_mul = gain_mul * (8.0 * M_LN10 / M_PI);
-- 
2.54.0

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

Reply via email to