whisper : NULL-guard CPU device lookup in make_buft_list (fix #3497)#3816
Open
TheBlueHouse75 wants to merge 1 commit into
Open
whisper : NULL-guard CPU device lookup in make_buft_list (fix #3497)#3816TheBlueHouse75 wants to merge 1 commit into
TheBlueHouse75 wants to merge 1 commit into
Conversation
…g#3497) Three call sites in `src/whisper.cpp` dereference the CPU backend device returned by GGML without checking for NULL. With GGML_BACKEND_DL=ON builds, the registry starts empty and an embedder that calls `whisper_init_*` or `whisper_vad_init_*` before any explicit `ggml_backend_load*()` invocation hits `GGML_ASSERT(device != NULL)` inside `ggml_backend_dev_backend_reg` and the process is killed with `__fastfail(7)` / `0xC0000409` on Windows. Reported in ggml-org#3497 (Flutter Windows embedder, same symptom). Independently reproduced on a Windows GGML_BACKEND_DL=ON build that calls `whisper_vad_init_from_file_with_params` before the dynamic CPU backend DLL is registered. Sites patched (line numbers from current master): - `make_buft_list` (line 1388): `cpu_dev` from `ggml_backend_dev_by_type` can be NULL. Return an empty buft list so the caller surfaces a NULL context instead of aborting. - `ggml_graph_compute_helper` (line 173): `backend` from `ggml_backend_init_by_type(CPU)` can be NULL. Return false so the caller surfaces a typed graph compute failure. - `whisper_exp_compute_token_level_timestamps_dtw` (line 8960): same pattern; skip the DTW step for this segment rather than abort. All three log a clear WHISPER_LOG_ERROR message pointing embedders at `ggml_backend_load_all()` / `ggml_backend_load()` as the fix on their side. Mirrors the existing NULL-guard upstream already has at line 1352 in `whisper_backend_init`. Build verified locally on macOS (CMake configure + build of the `whisper` shared library target, 0 warnings).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three call sites in `src/whisper.cpp` dereference the CPU backend device returned by GGML without checking for NULL. With `GGML_BACKEND_DL=ON` builds, the registry starts empty (no backend is statically linked into `ggml-base`), and an embedder that calls `whisper_init_` or `whisper_vad_init_` before an explicit `ggml_backend_load*()` invocation hits `GGML_ASSERT(device != NULL)` inside `ggml_backend_dev_backend_reg`. On Windows the process is killed with `__fastfail(7)` (status `0xC0000409`, `FAST_FAIL_FATAL_APP_EXIT`) with no chance for the application to recover.
Closes #3497 (same symptom, Flutter Windows embedder).
Repro
Any `BUILD_SHARED_LIBS=ON` + `GGML_BACKEND_DL=ON` build, on a host without a CPU backend DLL pre-loaded by `ggml_backend_load_all()`:
```c
// 1. Process starts. ggml-base.dll registry is empty (no static GGML_USE_CPU).
// 2. Embedder calls:
struct whisper_vad_context_params p = whisper_vad_default_context_params();
p.use_gpu = false;
whisper_vad_init_from_file_with_params("silero.gguf", p);
// → make_buft_list → ggml_backend_dev_by_type(CPU) → NULL
// → ggml_backend_dev_backend_reg(NULL) → assert → __fastfail(7)
```
I hit this on a Windows MSI build that calls `whisper_vad_init_from_file_with_params` for Silero VAD before the main `whisper_init_*`. Full WinDbg dump + stack trace at https://github.com/TheBlueHouse75/simple-flow/tree/report/whisper-rs-vad-gpu-null-2026-05-19/reports/windows-whisper-rs-vad-gpu-null-2026-05-19 .
Patch
All three log a clear `WHISPER_LOG_ERROR` message pointing embedders at `ggml_backend_load_all()` / `ggml_backend_load()` as the fix on their side. This mirrors the existing NULL-guard already present at line 1352 (`whisper_backend_init`).
Test plan
Why this matters
`GGML_ASSERT(device != NULL)` is the right invariant for internal code, but the C public API (`whisper_init_`, `whisper_vad_init_`) is reachable by embedders that may not know they must call `ggml_backend_load_all()` first — especially with the new VAD entry points (`whisper_vad_init_from_file_with_params`) shipped in 1.8.x. A process abort from inside a public C API call is hard to recover from for any high-level binding (Flutter, Rust, Python, …). Returning a NULL context + logging the error lets the binding surface a typed error to userland.
Happy to refactor (e.g. extract a shared `get_cpu_backend_or_log` helper) if you'd prefer. Kept the patches local and small for review.