fix(security): prevent infinite loop in split_audio with NaN audio sa… (#46463)

This commit is contained in:
Juan Pérez de Algaba
2026-06-23 10:24:51 +00:00
committed by GitHub
parent 20b5af55c1
commit 83fa302ca4
2 changed files with 43 additions and 2 deletions
+7 -2
View File
@@ -378,6 +378,11 @@ def split_audio(
audio_data, search_start, search_end, min_energy_window_size
)
# Guarantee forward progress: if split_point didn't advance,
# fall back to the hard chunk boundary.
if split_point <= i:
split_point = min(i + chunk_size, audio_data.shape[-1])
# Extract chunk up to the split point
chunks.append(audio_data[..., i:split_point])
i = split_point
@@ -423,12 +428,12 @@ def find_split_point(
# Calculate RMS energy in small windows
min_energy = math.inf
quietest_idx = 0
quietest_idx = start_idx
for i in range(0, len(segment) - min_energy_window, min_energy_window):
window = segment[i : i + min_energy_window]
energy = (window**2).mean() ** 0.5
if energy < min_energy:
if not math.isnan(energy) and energy < min_energy:
quietest_idx = i + start_idx
min_energy = energy