Repository navigation
fix(engine): SAPI 兜底改用 stdin 传文本,不再把回复拼进 PowerShell 脚本 - #11
Merged
Merged
Conversation
Windows 离线 TTS 兜底(engine/engine.py 的 _sapi_pcm)此前把待合成文本 直接拼进 -Command 的脚本字符串里。待合成文本来自模型回复,是可被外部 内容影响的数据,拼进脚本等于让数据参与语法解析。 改法: - 脚本主体提成常量 _SAPI_PS,内容固定,不含任何外部字符串 - 文本只走标准输入(StreamReader(OpenStandardInput) + ReadToEnd) - 输出路径只走环境变量 CURA_SAPI_OUT - powershell 失败时显式检查 returncode 并抛出 stderr 摘要, 不再拿一个可能不存在的 wav 去读 新增 tests/test-tts-inject.mjs(49 条断言): - 静态:脚本是常量、无 here-string 拼接、调用侧只用 input=、 全文件 -Command 的实参不含拼接表达式且只出现一处 - 动态:直接 import engine 调生产函数 _sapi_pcm,喂 here-string 闭合、 \$(...) 子表达式、分号串联、看似参数名的 "-Text"、中文换行五类文本, 断言都能正常合成且注入内容未被执行 - 非 Windows 或缺 python/powershell 时明说跳过,不计为通过
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.
为什么改
dshopen(polang233/dsh-plugin-index#460)的维护者指出,Windows 离线 TTS 兜底把模型回复拼进 PowerShell 命令。
这不是风格问题。待合成文本来自模型回复,是可被外部内容影响的数据(QQ 里对方说的话会被喂进去)。旧实现长这样:
here-string 只做行首
'@判定,文本参与脚本语法解析,攻击面客观存在。改了什么
engine/engine.py:_SAPI_PS,内容固定,不含任何外部字符串StreamReader([Console]::OpenStandardInput())+ReadToEnd()CURA_SAPI_OUTreturncode并抛出 stderr 摘要,不再拿一个可能不存在的 wav 去读(那只会得到更难懂的 IOError,掩盖真正原因)测试
新增
tests/test-tts-inject.mjs,49 条断言,已加进tests/all.mjs(第 10 套)。静态(代码形态)
_SAPI_PS存在,且常量体内无+拼接、无{}占位$s.Speak(@',改为$s.Speak($text)input=text.encode(...),-Command的实参必须是常量-Command的实参不得含拼接表达式,且只允许出现一处动态(真跑)
不是复刻调用逻辑,而是
import engine直接调生产函数_sapi_pcm,喂五类文本:$(New-Item ...)hi; New-Item ...-Text每个断言 rc==0、音频长度足够、注入的 marker 文件不存在。
变异自证(双向)
input=text.encode("utf-8")→input=None:静态组报「必须用 input= 把文本喂给 stdin」engine.py:报「找不到 _SAPI_PS 常量」env=env(静态断言抓不到):动态组报探针 rc=1CI 的诚实边界:CI 是 ubuntu-latest,没有 powershell 也没有 python。第 4/5 组会打印「跳过动态注入验证」并且不计为通过。静态断言在 CI 上照常全跑。本机 Windows 上两组都真跑了。
完整测试
node tests/all.mjs→ 10 套全过(32561ms)。已知但不属于本次改动
lib/chat.js:161、lib/index.js:541、lib/rules-remote.js:579走的是powershell -File say.ps1 -Text <value>,值经 argv 传递、不进脚本语法,不是注入。一个边角情况:如果值恰好是-Text这种形如参数名的字符串,PowerShell 会报缺参数。这是健壮性问题不是安全问题,本次未动。我没有做的事
engine/.scratch/engine.wip.py(未跟踪、不在 npm files[] 里,非生产代码)