From 082d6f6edbd28320e33a8d2e0f146e88293c6a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Wed, 25 Nov 2026 02:43:08 +0000 Subject: [PATCH] fix(cli): a whisper model is named by one plain file-name part, never a path or link (#8755) --- .../cli/src/whisper/manager.model.test.ts | 20 +++++++++++++++++++ packages/cli/src/whisper/manager.ts | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/packages/cli/src/whisper/manager.model.test.ts b/packages/cli/src/whisper/manager.model.test.ts index 8c6ee9ec1e..4a5639409d 100644 --- a/packages/cli/src/whisper/manager.model.test.ts +++ b/packages/cli/src/whisper/manager.model.test.ts @@ -124,6 +124,26 @@ it.skipIf(!process.getuid)( }, ); +// fails without the fix: "tiny.bin?/../…/planted" downloaded the tiny model to planted.bin outside the models folder. +it("refuses a model name that is not one plain file-name part, before any file or download", async () => { + for (const model of [ + "tiny.bin?/../../../outside/planted", + "../x", + "a/b", + "a\\b", + "tiny#x", + "tiny%2e", + "tiny..en", + "..", + ".x", + "", + ]) { + await expect(ensureModel(model)).rejects.toThrow(/is not a whisper model name/); + } + expect(vi.mocked(downloadFile)).not.toHaveBeenCalled(); + expect(readdirSync(modelsDir)).toEqual([]); +}); + // fails without the fix: a same-size file at a pinned model's name was used as the model, never checked. it("downloads a pinned model again when the cached file has the right size but other bytes", async () => { writeFileSync(tiny, ""); diff --git a/packages/cli/src/whisper/manager.ts b/packages/cli/src/whisper/manager.ts index 2dbc4c62bf..ba3737b1ed 100644 --- a/packages/cli/src/whisper/manager.ts +++ b/packages/cli/src/whisper/manager.ts @@ -48,6 +48,7 @@ export function isWhisperUnavailable(err: unknown): err is WhisperUnavailableErr } const MODEL_REVISION = "5359861c739e955e79d9a303bcbc70fb988958b1"; +const ONE_PLAIN_FILE_NAME_PART = /^(?!.*\.\.)[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/; function getModelUrl(model: string): string { return `https://huggingface.co/ggerganov/whisper.cpp/resolve/${MODEL_REVISION}/ggml-${model}.bin`; @@ -343,6 +344,11 @@ export async function ensureModel( onDownloadProgress?: (receivedBytes: number, totalBytes: number | null) => void; }, ): Promise { + if (!ONE_PLAIN_FILE_NAME_PART.test(model)) { + throw new Error( + `"${model}" is not a whisper model name. Use a name such as small.en or large-v3-turbo.`, + ); + } const modelPath = join(MODELS_DIR, `ggml-${model}.bin`); const pin = PINNED_MODELS.get(model); ensurePrivateCacheDir(MODELS_DIR, hyperframesCacheDir());