Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions clip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "ggml_extend.hpp"
#include "model.h"

#include <filesystem>

/*================================================== CLIPTokenizer ===================================================*/

std::pair<std::unordered_map<std::string, float>, std::string> extract_and_remove_lora(std::string text) {
Expand All @@ -21,6 +23,17 @@ std::pair<std::unordered_map<std::string, float>, std::string> extract_and_remov
continue;
}

// allow relative paths, but avoid traversing outside the base directory
auto path = std::filesystem::path(filename).lexically_normal();
if (path.empty() || *path.begin() == ".") {
LOG_WARN("ignoring LoRA with empty filename");
continue;
} else if (*path.begin() == ".." || path.has_root_directory()) {
LOG_WARN("ignoring LoRA \"%s\" outside the LoRA model directory", filename.c_str());
continue;
}
filename = path.string();

if (filename2multiplier.find(filename) == filename2multiplier.end()) {
filename2multiplier[filename] = multiplier;
} else {
Expand Down
Loading