chore: TaskData增加OcrTask的ocrReplace合法性检查 (#11878)

* chore: TaskData增加OcrTask的ocrReplace合法性检查

* docs: 加点注释
This commit is contained in:
status102
2025-02-17 09:25:44 +08:00
committed by GitHub
parent 2703fb3fcb
commit a3c68c74e9

View File

@@ -2,6 +2,7 @@
#include <algorithm>
#include <meojson/json.hpp>
#include <regex>
#ifdef ASST_DEBUG
#include <queue>
@@ -185,6 +186,20 @@ bool asst::TaskData::lazy_parse(const json::value& json)
Log.error("Task", name, "with Count method has empty color_scales");
validity = false;
}
// 用于解决 a8d68dd72df6eef1d2f8feed3883299922ec1a17 类似的潜在regex非法问题
if (auto ocr_task = std::dynamic_pointer_cast<OcrTaskInfo>(task);
task->algorithm == AlgorithmType::OcrDetect) {
for (const auto& [regex, new_str] : ocr_task->replace_map) {
try {
std::regex _(regex);
}
catch (const std::regex_error& e) {
Log.error("Task", name, "has invalid regex:", regex, ":", e.what());
validity = false;
break;
}
}
}
}
if (checking_task_set.size() > MAX_CHECKING_SIZE) {
// 生成超出上限一般是出现了会导致无限隐式生成的任务。比如 "#self@LoadingText". 这里给个警告.