Skip to content

Commit 8a68336

Browse files
committed
fix: do not accept LoRA paths outside --lora-model-dir
1 parent d05e46c commit 8a68336

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

clip.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "ggml_extend.hpp"
55
#include "model.h"
66

7+
#include <filesystem>
8+
79
/*================================================== CLIPTokenizer ===================================================*/
810

911
__STATIC_INLINE__ std::pair<std::unordered_map<std::string, float>, std::string> extract_and_remove_lora(std::string text) {
@@ -21,6 +23,17 @@ __STATIC_INLINE__ std::pair<std::unordered_map<std::string, float>, std::string>
2123
continue;
2224
}
2325

26+
// allow relative paths, but avoid traversing outside the base directory
27+
auto path = std::filesystem::path(filename).lexically_normal();
28+
if (path.empty() || *path.begin() == ".") {
29+
LOG_WARN("ignoring LoRA with empty filename");
30+
continue;
31+
} else if (*path.begin() == ".." || path.has_root_directory()) {
32+
LOG_WARN("ignoring LoRA \"%s\" outside the LoRA model directory", filename.c_str());
33+
continue;
34+
}
35+
filename = path.string();
36+
2437
if (filename2multiplier.find(filename) == filename2multiplier.end()) {
2538
filename2multiplier[filename] = multiplier;
2639
} else {

0 commit comments

Comments
 (0)