mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 08:32:45 +00:00
fix(cli): a whisper model is named by one plain file-name part, never a path or link (#8755)
This commit is contained in:
@@ -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, "");
|
||||
|
||||
@@ -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<string> {
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user