Skip to content

Commit f768007

Browse files
committed
fix: Validate model_name When Loading Model from Repository
This change adds additional validation of user input `model_name` prior to using to load a model from the repository.
1 parent d274607 commit f768007

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

  • python/openai/openai_frontend/engine/utils

python/openai/openai_frontend/engine/utils/triton.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import os
2929
import re
3030
from dataclasses import asdict, dataclass, field
31+
from pathlib import Path
3132
from typing import Iterable, List, Optional, Union
3233

3334
import numpy as np
@@ -356,13 +357,25 @@ def _get_guided_json_from_tool(
356357
def _get_vllm_lora_names(
357358
model_repository: str | list[str], model_name: str, model_version: int
358359
) -> None | List[str]:
360+
if (
361+
len(model_name) == 0
362+
or model_name.isspace()
363+
or "/" in model_name
364+
or "\\" in model_name
365+
):
366+
raise ValueError(
367+
f"Invalid model name: '{model_name}'. Model names must be valid file-system-path segment names."
368+
)
359369
lora_names = []
360370
repo_paths = model_repository
361371
if isinstance(repo_paths, str):
362372
repo_paths = [repo_paths]
363373
for repo_path in repo_paths:
364374
model_path = os.path.join(repo_path, model_name)
365-
if os.path.normpath(model_path) != model_path:
375+
if (
376+
(not Path(model_path).is_relative_to(repo_path))
377+
or (os.path.normpath(model_path) != model_path)
378+
):
366379
raise ValueError(
367380
f"Invalid model name: '{model_name}'. Model names must be valid file-system-path segment names."
368381
)

0 commit comments

Comments
 (0)