mirror of
https://github.com/RVC-Boss/GPT-SoVITS.git
synced 2026-04-29 21:00:42 +08:00
fix: 修复 API 输入验证和参数处理中的多个缺陷
1. 修复 handle_change 中 `or` 应为 `and` 的逻辑错误(api.py)
- `path != "" or path is not None` 恒为 True,导致未传递的参数
以 None/空值覆盖已有的有效配置
2. 修复 DefaultRefer.__init__ 忽略构造函数参数(api.py)
- 构造函数声明了 path/text/language 参数但未使用,直接引用
全局 args 变量,导致类无法正确复用
3. 修复 GET /tts 端点参数为 None 时 AttributeError(api_v2.py)
- text_lang 和 prompt_lang 默认值为 None,未提供时直接调用
None.lower() 导致崩溃
4. 替换 eval() 为安全的字符串比较(inference_webui.py)
- eval() 会执行任意代码,当环境变量被恶意设置时存在代码
注入风险,改用安全的字符串比较
Made-with: Cursor
This commit is contained in:
parent
2d9193b0d3
commit
6fc6148f8d
@ -84,10 +84,10 @@ bert_path = os.environ.get("bert_path", "GPT_SoVITS/pretrained_models/chinese-ro
|
||||
infer_ttswebui = os.environ.get("infer_ttswebui", 9872)
|
||||
infer_ttswebui = int(infer_ttswebui)
|
||||
is_share = os.environ.get("is_share", "False")
|
||||
is_share = eval(is_share)
|
||||
is_share = is_share.lower() in ("true", "1", "yes")
|
||||
if "_CUDA_VISIBLE_DEVICES" in os.environ:
|
||||
os.environ["CUDA_VISIBLE_DEVICES"] = os.environ["_CUDA_VISIBLE_DEVICES"]
|
||||
is_half = eval(os.environ.get("is_half", "True")) and torch.cuda.is_available()
|
||||
is_half = os.environ.get("is_half", "True").lower() in ("true", "1", "yes") and torch.cuda.is_available()
|
||||
# is_half=False
|
||||
punctuation = set(["!", "?", "…", ",", ".", "-", " "])
|
||||
import gradio as gr
|
||||
|
||||
12
api.py
12
api.py
@ -176,9 +176,9 @@ import subprocess
|
||||
|
||||
class DefaultRefer:
|
||||
def __init__(self, path, text, language):
|
||||
self.path = args.default_refer_path
|
||||
self.text = args.default_refer_text
|
||||
self.language = args.default_refer_language
|
||||
self.path = path
|
||||
self.text = text
|
||||
self.language = language
|
||||
|
||||
def is_ready(self) -> bool:
|
||||
return is_full(self.path, self.text, self.language)
|
||||
@ -1082,11 +1082,11 @@ def handle_change(path, text, language):
|
||||
{"code": 400, "message": '缺少任意一项以下参数: "path", "text", "language"'}, status_code=400
|
||||
)
|
||||
|
||||
if path != "" or path is not None:
|
||||
if path != "" and path is not None:
|
||||
default_refer.path = path
|
||||
if text != "" or text is not None:
|
||||
if text != "" and text is not None:
|
||||
default_refer.text = text
|
||||
if language != "" or language is not None:
|
||||
if language != "" and language is not None:
|
||||
default_refer.language = language
|
||||
|
||||
logger.info(f"当前默认参考音频路径: {default_refer.path}")
|
||||
|
||||
@ -481,11 +481,11 @@ async def tts_get_endpoint(
|
||||
):
|
||||
req = {
|
||||
"text": text,
|
||||
"text_lang": text_lang.lower(),
|
||||
"text_lang": text_lang.lower() if text_lang else "",
|
||||
"ref_audio_path": ref_audio_path,
|
||||
"aux_ref_audio_paths": aux_ref_audio_paths,
|
||||
"prompt_text": prompt_text,
|
||||
"prompt_lang": prompt_lang.lower(),
|
||||
"prompt_lang": prompt_lang.lower() if prompt_lang else "",
|
||||
"top_k": top_k,
|
||||
"top_p": top_p,
|
||||
"temperature": temperature,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user