You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
forced_align (CPU) segfaults when frames * (2*targets+1) exceeds 2^31: 32-bit loop index overflow #4208
torchaudio.functional.forced_align (CPU) crashes the whole process with SIGSEGV when frames * (2 * target_length + 1) exceeds 2^31. This is reachable with realistic inputs: character-level CTC alignment (WhisperX-style) of a ~20-minute chunk of dense speech at 50 fps crosses the limit (we hit it in production aligning a German podcast).
src/libtorchaudio/forced_align/cpu/compute.cpp, the backPtr_a init loop uses a 32-bit loop index against a 64-bit trip count:
auto backPtr_a = newint8_t[T * S]; // T, S are int64_t -- allocation is finefor (int i = 0; i < T * S; i++) { // int i overflows at 2^31 (UB)
backPtr_a[i] = -1;
}
Once i wraps to INT_MIN, the store lands at backPtr_a - 2^31 bytes. The macOS crash report confirms this exactly: fault address = buffer base − 0x80000000, as a byte write inside forced_align_impl<float, int>:
This also explains why int64 targets crash identically — the dispatch only changes target_t, not the init loop. The alphas_a init loop two lines above uses the same int i < 2 * S idiom (not practically reachable today, but the same latent pattern).
The bug is platform-independent (plain C++ signed-overflow UB); it is present in current main (c0cbdb9).
Correction (2026-08-04): an earlier version of this line said the bug went back to 2.8. It does not. #4021 (ea7855b), which introduced the raw array and the int fill loop, merged 2025-08-11 — five days after v2.8.0 shipped on 2025-08-06. v2.8.0 still carries the safe torch::Tensor backPtr = torch::empty({T, S}, torch::kInt8).fill_(-1). The affected range is 2.9.0 through 2.11.0.
Fix
One-liner: make the loop indices int64_t. PR incoming.
Versions
torchaudio 2.11.0 (also inspected current main, c0cbdb9)
torch 2.13.0
Python 3.12.8, macOS 26.5 (arm64, M1 Max) — but the overflow is platform-independent
Activity
Own the DP buffers instead of widening their init loops
Own the DP buffers, and size them only after validating the input
Own the DP buffers, and size them only after validating the input
Align words with a numpy Viterbi instead of torchaudio's kernel